Cant reference DropdownList in a DetailsView TemplateField
Posted on 2007-04-05
(using ASP.NET with C#)
I have a Gridview which uses a DetailsView for editing.
The DetailsView contains a DropdownList which is inside a TemplateField.
When the DetailsView loads I want to pre-select the correct DropdownList item as it currently just defaults to the first item.
I am trying to do this in the "GridView1_SelectedIndexChanged" event. I cant seem to get FindControl to work.
This doesnt work:
DetailsViewRow row = DetailsView1.Rows[e.RowIndex];
DropDownList d = row.FindControl("ddlLinkType") as DropDownList;
((DropDownList)((DetailsView)sender).FindControl("ddlLinkType")).SelectedIndex = 2;
What am I doing wrong?
Please advise - Thanks!