更新时间:2022-12-16 14:58:36
您没有在DataList本身上找到控件.您可以在DataList的每个DataListItem上执行此操作.请参考下面的代码:
You dont find the control on the DataList itself. You do it on every DataListItem of the DataList. Refer to the code below:
(DropDownList)DataList1.Items[0].FindControl("ddlcountry");
FindControl
需要知道它正在查找哪个项目,因为DataLis
t包含模板中每个控件的许多副本.您需要对DataLis
t中的所有项目进行迭代以找到下拉菜单并对其进行操作,您可以使用下面的代码,
FindControl
needs to know which Item it is looking in because aDataLis
t contains many copies of each control that is in a template.You need to iterate all items inDataLis
t to find the dropdown and manipulate them, you can use the code below,
foreach(DataListItem dlistItem in DataList1.Items)
{
DropDownList ddlcountry= dlistItem.item[i].
findControl("ddlcountry") as DropDownList;
if(ddlcountry!=null)
{
int id=Convert.ToInt32(ddlcountry.SelectedValue);
}
}
希望这会有所帮助.
Hope this will help.