! am having a nested DataList
and I want to bind inner DataList
on button
event, but it's not working, anyone have an idea?
DataList2.FindControl("DataList3").DataBind();
! am having a nested DataList
and I want to bind inner DataList
on button
event, but it's not working, anyone have an idea?
DataList2.FindControl("DataList3").DataBind();
Use this code to Bind
Inner DataList
:
protected void DataList2_ItemDataBound(object sender, DataListItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.Item) ||
(e.Item.ItemType == ListItemType.AlternatingItem))
{
// get inner datalist
DataList dl3 = e.Item.FindControl("DataList3") as DataList;
// bind inner datalist with data source
dl3.DataSource = dt; // DataTable that contains data
dl3.DataBind();
}
}
Note:
Make sure you have entered this event OnItemDataBound="DataList2_ItemDataBound"
like this:
<asp:DataList ID="DataList2" runat="server" OnItemDataBound="DataList2_ItemDataBound">
Try to cast it with datalist