Jackery Xu
Jackery Xu

Reputation: 402

Get selected user choice from a list of DropDownLists displayed via a Repeater

Right now I have a List<> of Dictionary elements that I display to a webpage. I use a Repeater for the entire List<> because the List<> length is arbitrary, and DropDownList for each Dictionary element. The user sees a Repeating list of DropDownLists and selects one Dictionary element from each of these said DropDownLists as their choice.

I would like to retrieve the Dictionary key of whatever the user's said choice is in each DropDownList. If this step is easier done afterwards, just retrieving everything is fine too, but my end goal is to isolate said keys and put them into an array. Right now I bind the List<> directly to the Repeater and everything displays fine, but I have no idea what to put into the function that is called when they press the final Submit button.

Cheers~

Upvotes: 1

Views: 558

Answers (1)

Charles Wesley
Charles Wesley

Reputation: 829

You can loop through each item in the repeater and then find the child control:

foreach (RepeaterItem ri in myRepeater.Items)
{
     DropDownList dropDownList = (DropDownList)ri.FindControl("dropDownList");
     string myValue = dropDownList.SelectedValue;
}

Upvotes: 3

Related Questions