我的页面中有一个Repeater,在数据绑定之后,我必须单击一个按钮才能在页面中回发,我需要在Repeater的所有数据中执行foreach
。在真实中,我必须将foreach
语句中的每个项目作为示例。
foreach (RepeaterItem itemEquipment in rptSpecialEquipments.Items)
{
// Get Data From My Repeater
}
最好的祝福,
米尔顿戈麦斯之家
这是你想要的吗?
foreach (RepeaterItem itemEquipment in rptSpecialEquipments.Items)
{
//to get the dropdown of each line
DropDownList yourDropDown = (DropDownList)item.FindControl("the name of your dropdown control here");
//to get the selected value of your dropdownlist
string value = yourDropDown.SelectedValue;
}
当您将RepeaterItem声明为itemEquipment时,应该在itemEquipment中找到(dropDownList)而不是item
所以正确的代码如下。我试图编辑上面的答案,但审查它的人被版本拒绝了。
foreach (RepeaterItem itemEquipment in rptSpecialEquipments.Items)
{
//to get the dropdown of each line
DropDownList yourDropDown = (DropDownList)itemEquipment.FindControl("the name of your dropdown control here");
//to get the selected value of your dropdownlist
string value = yourDropDown.SelectedValue;
}