!我有一个嵌套DataList
,我想DataList
在button
事件上绑定内部,但它不起作用,有人知道吗?
DataList2.FindControl("DataList3").DataBind();
!我有一个嵌套DataList
,我想DataList
在button
事件上绑定内部,但它不起作用,有人知道吗?
DataList2.FindControl("DataList3").DataBind();
将此代码用于Bind
内部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();
}
}
注意:
确保您已OnItemDataBound="DataList2_ItemDataBound"
像这样输入此事件:
<asp:DataList ID="DataList2" runat="server" OnItemDataBound="DataList2_ItemDataBound">
Try to cast it with datalist
((DataList)DataList2.FindControl("DataList3")).DataBind();