Get Repeater data with foreach

…衆ロ難τιáo~ 提交于 2019-12-11 02:01:59

问题


I have a Repeater in my page and after databinding, I have to click on a button to postback in page, and I need to do a foreach in all data from my Repeater. In true I have to get each item inside foreach statment as example.

foreach (RepeaterItem itemEquipment in rptSpecialEquipments.Items)
{
   // Get Data From My Repeater
}

Best Regards,

Milton Câmara Gomes


回答1:


Is this what you want?

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



回答2:


when you are declaring RepeaterItem as itemEquipment then (dropDownList) should be be found in itemEquipment not item

so correct code would be as below. I tried to edit the answer above but the person who reviewed it rejected by edition.

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


来源:https://stackoverflow.com/questions/8915758/get-repeater-data-with-foreach

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!