Solved

Cant reference DropdownList in a DetailsView TemplateField

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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 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.

810 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