C# 使用foreach获取中继器数据

C# 使用foreach获取中继器数据,c#,asp.net,repeater,C#,Asp.net,Repeater,我的页面中有一个中继器,在数据绑定后,我必须单击一个按钮在页面中发回,并且我需要对来自中继器的所有数据执行foreach。 事实上,我必须把每个项目都放在foreachstatment中作为例子 foreach (RepeaterItem itemEquipment in rptSpecialEquipments.Items) { // Get Data From My Repeater } 致以最良好的祝愿 米尔顿·卡马拉·戈麦斯这就是你想要的吗 foreach (Repeat

我的页面中有一个中继器,在数据绑定后,我必须单击一个按钮在页面中发回,并且我需要对来自中继器的所有数据执行
foreach
。 事实上,我必须把每个项目都放在
foreach
statment中作为例子

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而不是item中找到(dropDownList)

所以正确的代码如下。 我试图编辑上面的答案,但审阅者拒绝了

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;
    }

您确定需要逐项查看整个列表吗?你在寻找所选项目吗?不,我真的需要一步一步地浏览整个列表,因为每个项目都有一个下拉列表。我必须知道选择了什么DropDownList项,如果是这样,我必须获取选择了DropDownList项的实际数据项。是的,但我也需要从RepeaterItem获取实际数据对象。我不明白您需要什么。“数据对象”是什么意思?听起来你需要
DataItem data=(DataItem)下拉列表