Thanks, but I have tried using e.RowIndex and EditIndex. I have also tried doing a recursive check on the Grid and even the whole Page, but still cannot find the DropDownList.
Main Topics
Browse All TopicsI have a problem, with GridView and TemplateFields. We have an application which creates maintenance screens based on an xml configuration file. The xml describes which fields to show, etc. This all works
However, we have a new requirement to add DropDownLists to some columns to enforce data integrity.
I have therefore added the relevant xml, and when creating the grid, create the column as a TemplateField and the EditItem as a DropDownList with its own SqlDataSource.
So far so good, this all works, the grid is displayed, the DropDownList appears, filled with the correct data, shows the correct initial item and lets the user select another.
Here is where I have problems. The when trying to get the value from the DropDownList in the RowUpdating event, I cant find it. Ive used FindControl to no avail. I create a RecursiveFindControl method that ran through every control on the page, and it cant find it. Ive tried peeking in the cell controls in the debugger and its just not there.
Can anyone help? Ive duplicated it in a simpler test page, with a test database.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
did you try the code ro rowindex as suggested above and in the line below taken from the below mentioned link
drdList = (DropDownList)(GridView1.R
http://programming.top54u.
well, EditItemTemplate is null because you set it dynamicly, it`s not using a EditItemTemplate.
What you should check is the content of GridView1.Rows[ e.RowIndex ]
i now suspect it<s has somthing to do with the BindGrid(); call, it i correctly understant it, the grid is constructed (and the dropdown) at this point. what if you call the BindGrid BEFORE finding the ddl?
No i dont think the page load is the problem, but we are getting closer to the source of the problem. i<m surprise the BindGrid() make the DropDownList "appear".
What happen if you leave the BindGrid(); at the end but call BuildGrid(); before finding the ddl? I worry it will still dont have your new value, but let`s try.
The other solution is to drop that dynamic control creation and uses standard item and edit templates (declaratively in the aspx file)
I jsut noticed this code.
void ddl_SelectedIndexChanged(o
{
DropDownList ddl = (DropDownList)sender;
Session["albumId_val"] = ddl.SelectedValue;
}
so i guess you are doing something like this has a workaround.
string val = Session["albumId_val"]
e.NewValues.Add("albumId",
if not, it could be a solution, since we cannot find the control right now...
That is wonderfull... (sarcasm)
I was thinking of retriving the ddl value trough the viewstate and i found this.
http://msdn.microsoft
So i got another idea, what if you call the BuildGrid in the page init instead of page load?
After investigation, it looks like the SelectedIndexChanged is not called because on the postback with update, the DropDownList doesn't exists, therefore the event doesn't exist.
As a workaround, I can add a javascript onchange event to the DropDownList which is called when the value changes. Is there a way I can pass this value back to the server and use it?
Asp.net generate a javascript function with the name "__doPostBack". this is the function that is called by all control when sending information to the server. So, you could use it in the javascript onchange event.
http://aspalliance.c
Business Accounts
Answer for Membership
by: davrob60Posted on 2009-03-06 at 06:31:03ID: 23816835
instead use e.RowIndex to extact the rox from the gridview and use find control on the extracted row
http://msdn.microsoft.c om/en-us/l ibrary/sys tem.web.ui .webcontro ls.gridvie wupdateeve ntargs_pro perties.as px
here an exemple.
http://www.daniweb .com/forum s/thread14 3909.html
and in case you prefear vb version:
http://social.msdn .microsoft .com/Forum s/en-US/vb language/ t hread/2536 897b-a251- 4f79-a8b9- b3bc9100f4 b7/