Hi,
-> Here this is sample code that describe that how asp.net handle parent child table relation and bind repeater with nested structure.
-> In this code only 1 level repeater is bind but you can bind more level.
Html side structure
<div> <ul> <asp:Repeater ID="RptMain" runat="server" OnItemDataBound="RptMain_ItemDataBound"> <ItemTemplate> <li> <%# Eval("ProjectName")%> </li> <ul> <asp:Repeater ID="rptSubCate" runat="server"> <ItemTemplate> <li> <%# Eval("CategoryName")%> </li> </ItemTemplate> </asp:Repeater> </ul> </ItemTemplate> <AlternatingItemTemplate> <li> <%# Eval("ProjectName")%> </li> <ul> <asp:Repeater ID="rptSubCate" runat="server"> <ItemTemplate> <li> <%# Eval("CategoryName")%> </li> </ItemTemplate> </asp:Repeater> </ul> </AlternatingItemTemplate> </asp:Repeater> </ul> </div>
Coding side structure
protected void Page_Load(object sender, EventArgs e) { common Obj = new common(); DataSet Ds = Obj.TestProcedure(); if (Ds != null) { DataRelation dRelation = new DataRelation("dRelation", Ds.Tables[0].Columns["ProjectId"], Ds.Tables[1].Columns["ProjectId"], false); Ds.Relations.Add(dRelation); RptMain.DataSource = Ds.Tables[0]; RptMain.DataBind(); } } protected void RptMain_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Repeater rptSubCate = e.Item.FindControl("rptSubCate") as Repeater;
rptSubCate.DataSource = ((DataRowView)e.Item.DataItem).CreateChildView("dRelation"); rptSubCate.DataBind(); } }
Enjoy Thanks
|
No responses found. Be the first to respond and make money from revenue sharing program.
|