Nesting Datalist
Use the .aspx code below to bind datalist inside a datalist.
<asp:DataList ID="lstPanels" runat="server" RepeatColumns="1" RepeatDirection="Horizontal"
DataKeyField="PanelID" OnItemDataBound="lstPanelsItemDataBound">
<asp:DataList ID="SubDataList" runat="server" RepeatColumns="1" RepeatDirection="Horizontal">
<ItemTemplate>
<ul><li><a class="various" href='<%# "TestDesc.aspx?Testid=" + Eval("TestID") %>'>
<%#Eval("TestName")%>
</a></li> </u>
</ItemTemplate>
</asp:DataList>
<ItemTemplate>
</ItemTemplate>
</asp:DataList>
Write the C# code to implement the functionality
protected void lstPanelsItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
int PanelID = Convert.ToInt32(lstPanels.DataKeys[e.Item.ItemIndex]);
// This will fetch the datakey on ItemDataBoundb event
DataList SubDataList = e.Item.FindControl("SubDataList") as DataList;
DataTable dtTests = GetDatatable(Convert.ToInt32(PanelID));
// GetDatatable is a function which will get the data into the datatable
if (dtTests.Rows.Count > 0)
{
SubDataList.DataSource = dtTests;
SubDataList.DataBind();
}
}
}
0 Comment(s)