C# 从中继器的模板获取控件
您需要使用ItemDataBound事件并在其中检查页脚C# 从中继器的模板获取控件,c#,C#,您需要使用ItemDataBound事件并在其中检查页脚 DropDownList ddlChangeUser = siteMapAsBulletedList.Items[0].FindControl("ddlChangeUser") as DropDownList; 谢谢你的回答,但是没有其他可能从FooterTemplate获取DropDownList吗?@senzacionale-没有,据我所知没有。这种方法有什么问题吗?我需要在if(ddlChangeUser!=null){中获取一
DropDownList ddlChangeUser = siteMapAsBulletedList.Items[0].FindControl("ddlChangeUser") as DropDownList;
谢谢你的回答,但是没有其他可能从FooterTemplate获取DropDownList吗?@senzacionale-没有,据我所知没有。这种方法有什么问题吗?我需要在if(ddlChangeUser!=null){中获取一些ID,但我无法获取它then@senzacionale-获取什么ID?为什么不能获取?@senzacionale抱歉,我看不出问题所在。如果{}block-post您获取的错误,您可以在其中包含任何代码,我将尝试引导您完成。
DropDownList ddlChangeUser = siteMapAsBulletedList.Items[0].FindControl("ddlChangeUser") as DropDownList;
siteMapAsBulletedList.ItemDataBound += new RepeaterItemEventHandler(siteMapAsBulletedList_ItemDataBound);
...
void siteMapAsBulletedList_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Footer)
{
DropDownList ddlChangeUser = (DropDownList)e.Item.FindControl("ddlChangeUser");
if (ddlChangeUser != null) {
...
}
}
}