Click to See Complete Forum and Search --> : FindControl help


David Flores
January 6th, 2003, 03:20 PM
I am having a little trouble with the FindControl function, it seems that its not working or I am doing something wrong. Here is my situation.

I have a DataGrid with the standard edit/update/cancel links, when the user clicks the edit link i process the message in the edit command function. in that function i set the EditItemIndex property, update then grid display, then I add a DropDownList control to one of the cells. I doubled checked with the FindControl function that it was added properly.

Now after the user clicks the Update link, I process the message in the appropiate function. I went to get the item selected from the DropDownList control that I added in the Edit command. But the FindControl functions retuns NULL.

Has anyone else had this problem? Or has a solution to it?

mikescham
January 7th, 2003, 09:23 AM
Because the dropdown list is added dynamically to the DataGrid it will not exist on postback. You have to add the control back into the datagrid (probably in the itemcreated event) on postback in order to use findcontrol. Another option is to include the dropdown as part of a template column and toggle its visible property...

David Flores
January 8th, 2003, 02:28 PM
Thanks Mike, I you verified what I found out with alittle more testing. I added the creation of the dropdown list in the ItemDataBound function since I only want it to appear for the selected/edit row. However this doesnt work. Do you have any other ideas? I dont really want to try the template column yet.

mikescham
January 10th, 2003, 03:04 PM
ItemDataBound will only be called when you call DataBind(). Try adding the dropdown list in the ItemCreated event.