- Home
- LLBLGen Pro
- LLBLGen Pro Runtime Framework
gridview bind data from more than two table
Joined: 29-Apr-2009
Hello All,
i am using LLBLGen 2.6 and Self Servicing
well by direct using SQLDATASOURCE i can bind my gridview from multiple table
i am using following sql query to execute
SELECT Orders.CustomerID, Customers.ContactName
FROM Orders INNER JOIN
Customers ON Orders.CustomerID = Customers.CustomerID
so i can get Following type of Output in gridview, without using a single line of code and i can also use built in facility, paging and sorting, and its works fine.
CUSTOMERID | CONTACTNAME
well now same thing i am doing by using LLBLGen 2.6 and self servicing
in above procedure in my gridview i have not taken any templatefiled. but if i am using llblgen i have to use template field to display data from more than one table,
this is my ASPX Page code
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
onrowdatabound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Customer ID">
<ItemTemplate>
<asp:Label ID="lblCustID" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Contact Name">
<ItemTemplate>
<asp:Label ID="lblName" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
and this is my CS code
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Northwind.CollectionClasses;
using Northwind.EntityClasses;
using Northwind.FactoryClasses;
using Northwind.HelperClasses;
using Northwind;
using Northwind.RelationClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
public partial class Default5 : System.Web.UI.Page
{
public CustomersCollection claCustomer = new CustomersCollection();
public OrdersCollection claOrder = new OrdersCollection();
public int intCount = 0;
protected void Page_Load(object sender, EventArgs e)
{
claOrder.GetMulti(null);
GridView1.DataSource = claOrder;
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblName = (Label)e.Row.Cells[0].FindControl("lblName");
string strCustName = GetCustomerNameByCustomerID(claOrder[intCount].CustomerId);
lblName.Text = strCustName;
Label lblCustID = (Label)e.Row.Cells[0].FindControl("lblCustID");
lblCustID.Text = claOrder[intCount].CustomerId.ToString();
}
intCount++;
}
catch (Exception ex)
{
}
}
public string GetCustomerNameByCustomerID(string strCustID)
{
CustomersCollection claCust = new CustomersCollection();
IPredicate Filter = (CustomersFields.CustomerId == strCustID);
claCust.GetMulti(Filter);
return claCust[0].ContactName.ToString();
}
}
by this way,i can bind data but i cannot use paging and sorting, for that i have to use extra coding and for each field i have to take template field (i.e. CustomerName,CustomerID)
is there any easier way to bind data in gridview, without using template field and row databound event.
It's much easier than this, please check the following threads: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=13769 http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=8716
Also I think you'll find our ASP.NET 2.0 databinding example solution very helpful. It has many databinding examples: http://www.llblgen.com/pages/secure/ListDownloads.aspx?ProductVersion=6 (not the CRUD one).
Joined: 29-Apr-2009
Walaa wrote:
It's much easier than this, please check the following threads: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=13769 http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=8716
Also I think you'll find our ASP.NET 2.0 databinding example solution very helpful. It has many databinding examples: http://www.llblgen.com/pages/secure/ListDownloads.aspx?ProductVersion=6 (not the CRUD one).
hi walaa,
i have tried following code but i am getting error, Object reference not set to an instance of an object.
ResultsetFields fields = new ResultsetFields(3);
fields.DefineField(OrdersFields.CustomerId, 0);
fields.DefineField(CustomersFields.ContactName,1);
IRelationCollection relations = new RelationCollection();
relations.Add(OrdersEntity.Relations.CustomersEntityUsingCustomerId,JoinHint.None);
DataTable dynamicList = new DataTable();
TypedListDAO dao = new TypedListDAO();
dao.GetMultiAsDataTable(fields, dynamicList, 0, null, null, relations, true, null, null, 0, 0);
can u correct me?
Joined: 29-Apr-2009
Walaa wrote:
It's much easier than this, please check the following threads: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=13769 http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=8716
Also I think you'll find our ASP.NET 2.0 databinding example solution very helpful. It has many databinding examples: http://www.llblgen.com/pages/secure/ListDownloads.aspx?ProductVersion=6 (not the CRUD one).
hello walaa,
sorry i was wrong,
i have make correction like this, now it is woking, ResultsetFields fields = new ResultsetFields(2);
well but problem is that, if i am click on paging,
i am getting following error
The GridView 'GridView1' fired event PageIndexChanging which wasn't handled.
is there any solution to overcome for paging and sorting in llblGen
Joined: 29-Apr-2009
manoj.sitapara wrote:
Walaa wrote:
It's much easier than this, please check the following threads: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=13769 http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=8716
Also I think you'll find our ASP.NET 2.0 databinding example solution very helpful. It has many databinding examples: http://www.llblgen.com/pages/secure/ListDownloads.aspx?ProductVersion=6 (not the CRUD one).
hello walaa,
sorry i was wrong,
i have make correction like this, now it is woking, ResultsetFields fields = new ResultsetFields(2);
well but problem is that, if i am click on paging,
i am getting following error
The GridView 'GridView1' fired event PageIndexChanging which wasn't handled.
is there any solution to overcome for paging and sorting in llblGen
Hello walaa, paging problem is also solved,
i have wrote following code
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
}
now it works. now i am searching for sorting.
Joined: 29-Apr-2009
manoj.sitapara wrote:
manoj.sitapara wrote:
Walaa wrote:
It's much easier than this, please check the following threads: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=13769 http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=8716
Also I think you'll find our ASP.NET 2.0 databinding example solution very helpful. It has many databinding examples: http://www.llblgen.com/pages/secure/ListDownloads.aspx?ProductVersion=6 (not the CRUD one).
hello walaa,
sorry i was wrong,
i have make correction like this, now it is woking, ResultsetFields fields = new ResultsetFields(2);
well but problem is that, if i am click on paging,
i am getting following error
The GridView 'GridView1' fired event PageIndexChanging which wasn't handled.
is there any solution to overcome for paging and sorting in llblGen
Hello walaa, paging problem is also solved,
i have wrote following code
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; }
now it works. now i am searching for sorting.
sorting is also working
as following
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dataTable = GridView1.DataSource as DataTable;
if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);
GridView1.DataSource = dataView;
GridView1.DataBind();
}
}
private string ConvertSortDirectionToSql(SortDirection sortDirection)
{
string newSortDirection = String.Empty;
switch (sortDirection)
{
case SortDirection.Ascending:
newSortDirection = "ASC";
break;
case SortDirection.Descending:
newSortDirection = "DESC";
break;
}
return newSortDirection;
}