I have Datalist and I am not able to find the footer controls in foreach loop. Any help?
protected void btnactualapprove_Click(object sender, EventArgs e)
{
foreach (DataListItem dli in dtaddedOrderItem.Items)
{
DataList dtaddedsubserviceitem = (DataList)dli.FindControl("dtaddedsubserviceitem");
foreach (DataListItem subdli in dtaddedsubserviceitem.Items)
{
DataList dtsuggestedlist = (DataList)subdli.FindControl("dtsuggestedlist");
if (dtsuggestedlist != null)
{
// not comming inside
}
}
}
}
I am not able to find dtsuggestedlist
which is in the footer of dtaddedsubserviceitem
datalist.
Here all time I am getting dtsuggestedlist
as null.
Structure is like as below
Datalist dtaddedOrderItem start
<ItemTemplate>
Datalist dtsuggestedlist start
<ItemTemplate>
</ItemTemplate>
<FooterTemplate>
Datalist dtsuggestedlist start
Datalist dtsuggestedlist end
</FooterTemplate>
Datalist dtsuggestedlist end
</ItemTemplate>
Datalist dtaddedOrderItem end
I am not able to find dtsuggestedlist which is in footer of dtsuggestedlist
Brief
<asp:DataList ID="dtaddedOrderItem" runat="server">
<ItemTemplate>
<asp:DataList ID="dtaddedsubserviceitem" runat="server" >
<ItemTemplate>
</ItemTemplate>
<FooterTemplate>
<asp:DataList ID="dtsuggestedlist" runat="server" >
<ItemTemplate>
</ItemTemplate>
</asp:DataList>
</FooterTemplate>
</asp:DataList>
</ItemTemplate>
</asp:DataList>
<asp:Button ID="btnactualapprove" OnClick="btnactualapprove_Click" />
You can't use a
foreach
because that will only enumerate items which type isItem
/AlternatingItem
and skip the header/footer etc. But you can useControls
.This should work(in general):
and this in your special case of nested DataLists:
Yes: