Reputation: 176
I have a number of drop down lists and buttons that are created dynamically. I need to write a piece of code that updates (in this case sets enabled to false) a drop down list after a user hits a certain button. Because everything is created dynamically I have to use Request.Form.AllKeys to find the ID of the drop down list. Which I am sussessfully able to do. However after I have found the ID I am unable to update the ddl in any way. How can I accomplish this?
For Each ddlID In Request.Form.AllKeys
If ddlID Like "ddl_*_" & number Then
'' Need to figure out how to control the ddl from this point
ddlID.
End If
Next
Upvotes: 0
Views: 134
Reputation: 9193
Leverage the FindControl Method and Cast the result as a DropDownList:
Dim yourDropDownInstance as DropDownList = CType(Page.FindControl("ddl_" & number), DropDownList))
Note 1: You pass in the ID into the FindControl Method.
Note 2: Use FindControl off of whatever control you added your DropDownLists to.
Upvotes: 2