Solved

Cant reference DropdownList in a DetailsView TemplateField

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 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.
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.

760 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

18 Experts available now in Live!

Get 1:1 Help Now