Solved

Cant reference DropdownList in a DetailsView TemplateField

Posted on 2007-04-05
2
1,106 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now