[RESOLVED]repeater in repeater

hi

i have a table in database,and each record of the table hase a type.

i want to display the fields of table,and group them by type field.

i have 2repeater.1 for type field,and 1 for all of another fields.

i want to have nested repeater,1 row for type,and the field of that type below

how can i do it?

 

TABLE1

YEAR     
SEMESTER

2001      1st

2001      2ND

2002      1st

2003      1st

2003      2nd

2. the semester should be grouped/show under the year like the sample below:

2001

     1st

     2nd

2002

     1st

2003

             1st

            2nd

i want this,please tell methe html codes and codebehind.

i want to do with c#

try this

<ul id="nav">
<asp:Repeater ID="dltMenuBar" runat="server"
onitemdatabound="dltMenuBar_ItemDataBound" >
<ItemTemplate>
<li><%#Eval("year") %>
<ul style="padding-top:8px;">
<asp:Repeater ID="dltMenuItems" runat="server">
<ItemTemplate>
<li><%#Eval("semister") %></li>
</ItemTemplate>
</asp:Repeater>
</ul>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>

protected void dltMenuBar_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
{
DataRowView drv = e.Item.DataItem as DataRowView;
Repeater innerDataList = e.Item.FindControl("dltMenuItems") as Repeater;
innerDataList.DataSource = drv.CreateChildView("yearsList");
innerDataList.DataBind();
}
}
public void getData()
{
SqlConnection myConnection = new SqlConnection("uid=sa;pwd=123;database=northwind");
SqlCommand myCommand = new SqlCommand("SELECT year FROM Table_1 where year IN ( SELECT year from Table_1 ) SELECT semister,year FROM Table_1 ", myConnection);

SqlDataAdapter ad = new SqlDataAdapter(myCommand);
DataSet ds = new DataSet();
ad.Fill(ds);
// Attach the relationship to the dataSet
ds.Relations.Add(new DataRelation("yearsList", ds.Tables[0].Columns["year"],
ds.Tables[1].Columns["year"]));
dltMenuBar.DataSource = ds.Tables[0];
dltMenuBar.DataBind();
}

Leave a Reply