Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to bind a Datalist inside a Datalist

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.16k
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: