Hello,
I am using Northwind DB and i have a gridview name gvwSelf and a Nested gridview gvwNested. What i do is i filter my dataset based on the
categoryName and accordingly display the result in the Gridview. Filteration works perfect however, i am unable to access my gvwNested...Pl..find my sample code below and please help me to find where am i going wrong..:(
<asp:GridView ID="gvwSelf" runat="server" AutoGenerateColumns="False" DataKeyNames="CategoryID">
<Columns>
<asp:BoundField DataField="CategoryName" HeaderText="Name" />
<asp:BoundField DataField="Description" HeaderText="Description" />
<asp:TemplateField>
<ItemTemplate >
<asp:GridView ID="gvwNested" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="CategoryID" HeaderText="ID" />
<asp:BoundField DataField="CategoryName" HeaderText="Name" />
<asp:BoundField DataField="Discription" HeaderText="Description" />
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
IN .CS Page:
private void BindGridView()
{
string str = "";
SqlConnection con = new SqlConnection(str);
string cmd = "Select * from categories";
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd,str);
da.Fill(ds);
DataTable tblData = ds.Tables[0];
tblData.DefaultView.RowFilter = "CategoryName = 'Beverages'";
gvwSelf.DataSource = tblData;
gvwSelf.DataBind();
GridView gvwnested = new GridView();
gvwnested = (GridView)gvwSelf.FindControl("gvwNested"); // I get gvwNested as NULL DataTable tblNested = ds.Tables[0];
tblNested.DefaultView.RowFilter = "CategoryName = 'Condiments'";
gvwnested.DataSource = tblNested; // Object Reference Error gvwnested.DataBind();
}
Also, i want to know how to display my gvwNested below my gvwSelf...also i want display header to each of them so that the sections are diffrentiated...
Please help
Best Regards,
Rohan Laghate