Solved

Cant reference DropdownList in a DetailsView TemplateField

Posted on 2007-04-05
2
1,111 Views
Last Modified: 2012-08-14
Hi,
(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;
    d.SelectedIndex=2;

Nor this:
    ((DropDownList)((DetailsView)sender).FindControl("ddlLinkType")).SelectedIndex = 2;

What am I doing wrong?
Please advise - Thanks!
0
Comment
Question by:astromex
2 Comments
 
LVL 2

Accepted Solution

by:
gjok earned 500 total points
ID: 18858907
Try this:
((DropDownList)((DetailsView)DetailsView1).FindControl("ddlLinkType")).SelectedIndex = SelLinkType;
0
 

Author Comment

by:astromex
ID: 18859100
Thanks - Thats fixed it!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question