PDA

View Full Version : getting dynamically created controls


Brett Bretterso
09-26-2005, 04:26 PM
Okay, so I'm making a page that queries a database and for every row that matches the criteria it creates a set of controls that allow for editing that row. Unfortunately I can't remember how to refer to dynamically created controls. The controls in each set follow a formula that allows me to get the id of each other control in the set, but I can't remember how to get dynamically created controls, that way when they hit the edit button for that set it will look at the other controls for that set and edit the row accordingly.

Code:
enddatum = placeDyEnd.SelectedItem.Value

What do I put instead of the bolded part? With some languages it would be something like: [stringofid].SelectedItem.Value. I already tried that and it didn't know what I was talking about. I also tried () instead of [], but that didn't work either.

Any help would be appreciated.

Brett Bretterson

Brett Bretterso
09-26-2005, 07:42 PM
I found it. You use the FindControl() function. If you have to do this please note that it doesn't like to do things like FindControl("foobar").SelectedValue. It will say that SelectedValue isn't a property of System.Web.UI.Control. A way around this is to put the found control into a dropdownlist and then get the selected value. Like this:

Dim myDDList1 As DropDownList = FindControl("foo")
If myDDList1.SelectedValue = "bar" Then
'whatever
End if