I have a repeater control that contains an ItemTemplate containing a databound label and a DropDownList control. With each iteration, I’d like to change the ID of the DropDownList with each iteration, in order to use the values as inputs upon submission. Can anyone tell me how this is usually done? Thanks.
I have a repeater control that contains an ItemTemplate containing a databound label and
Share
This is done for you automatically, see the Using the NamingContainer Property to Determine a Control’s Naming Container for details on how it works.
I imagine that probably isn’t exactly what you are looking for though. In order to get the values from the drop downs, you should loop through the items in the repeater and use the FindControl method to find the drop down based on the ID you specified.
Edit: Based on your comment, I would not renamed the drop down list to be the ID in your database. Instead you should put a hidden literal control in your repeater. Set the value of that to the ID of your database record. Then get the ID the same way you get the value of the drop down list.
Your aspx markup will look like this