Here is Sample code of Aspx page of Gridview.
I have used here only Label inside the Gridview you can use any Asp Control inside the Gridview It's much easy.
Sample.aspx code:
<asp:GridView ID="gvCat" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
Category
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblcat" runat="server" Text='<%#Eval("CatName") %>'></asp:Label>
<asp:GridView ID="gvSubCat" runat="server" DataKeyNames="gvSubCat" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="SubCatName" HeaderText="SubCatName" />
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Sample.aspx.cs:
public partial class Default2 : System.Web.UI.Page
{
MasterData clsMaster = new MasterData();
protected void Page_Load(object sender, EventArgs e)
{
dlCat.DataSource = clsMaster.SelectDataCat();
dlCat.DataBind();
}
private void BindGrid(GridView GV, int SubCatID)
{
string qry = "SELECT * FROM SubCategoryMaster WHERE CatId=" + SubCatID;
SqlDataAdapter adp = new SqlDataAdapter(qry, ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
DataTable dt = new DataTable();
adp.Fill(dt);
GV.DataSource = dt;
GV.DataBind();
}
protected void dlCat_ItemDataBound(object sender, DataListItemEventArgs e)
{
GridView GV1 = (GridView)e.Item.FindControl("gvSubCat");
BindGrid(GV1,int.Parse( dlCat.DataKeys[e.Item.ItemIndex].ToString()));
}
}
Subscribe to:
Post Comments (Atom)
1 comments:
I want to the code for how to use datalist inside datalist
Post a Comment