C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » ASP.NET/Web Applications »

Dataset relation to bind nested repeater


Posted Date: 29 Oct 2009    Resource Type: Articles    Category: ASP.NET/Web Applications
Author: soniumeshMember Level: Gold    
Rating: 1 out of 5Points: 10



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





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Dataset relation for patent child relation  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Web site access permission.
Previous Resource: Polymorphism in C#.Net
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET/Web Applications


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use