1

!我有一个嵌套DataList,我想DataListbutton事件上绑定内部,但它不起作用,有人知道吗?

DataList2.FindControl("DataList3").DataBind();
4

2 回答 2

1

将此代码用于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">

于 2017-06-14T09:42:16.177 回答
0

Try to cast it with datalist

((DataList)DataList2.FindControl("DataList3")).DataBind();
于 2011-12-30T04:05:16.240 回答