Solved

Cant reference DropdownList in a DetailsView TemplateField

Posted on 2007-04-05
2
1,114 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

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…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

624 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