mcamara
mcamara

Reputation: 753

Get Repeater data with foreach

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

Upvotes: 2

Views: 25960

Answers (2)

Ashish Yadav
Ashish Yadav

Reputation: 11

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

Upvotes: 1

gabsferreira
gabsferreira

Reputation: 3147

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

Upvotes: 5

Related Questions