Solved

How to programmatically select dropdownlist item (asp.net / web)

Posted on 2013-05-29
3
745 Views
Last Modified: 2013-06-03
(code behind is in C#, btw)

drop down list has several values.

In the code behind I want to programmatically select one of them based-upon the "friendly" value, not the ID:

rendered html:
<select name="ctl08$ddlBpoType" id="ctl08_ddlBpoType" style="width:300px;">
	<option selected="selected" value="0">Unassigned</option>
	<option value="223">3rd Opinion</option>
	<option value="219">Appraisal</option>
	<option value="1809">CMA</option>
	<option value="222">Drive By</option>
	<option value="218">ListingAgent</option>
	<option value="913">ListingAgent Updated</option>
	<option value="220">Supplemental</option>
	<option value="1927">VRR</option>

</select>

Open in new window



ddlBpoType.SelectedValue = "Supplemental";

does not work, but

ddlBpoType.SelectedValue = "220";

does.


Except i don't want to use "220" because it might not be "220".

I want to get to the "220" value by using the friendly name of "Supplemental".
0
Comment
Question by:knowlton
3 Comments
 
LVL 19

Accepted Solution

by:
Manoj Patil earned 250 total points
ID: 39206800
Try this
string selectedItem= ddlBpoType.SelectedItem.Text

AND

If you want to set the  item as selected in DropDown then try this

dropdownlist.Items.FindByValue(value).Selected = true;


Get some more ideas about DropDownList
http://asp-net-example.blogspot.in/2009/03/how-to-find-item-by-value-in.html
0
 
LVL 13

Assisted Solution

by:Naman Goel
Naman Goel earned 250 total points
ID: 39208665
You can make use of FindByText method and take index of ListItem in dropdownlist using IndexOf method :

Dim li As ListItem

        li = ddlBpoType.Items.FindByText(CycleNo1.Text)
        ddlBpoType.SelectedIndex = ddlBpoType.Items.IndexOf(li)

Open in new window

0
 
LVL 5

Author Closing Comment

by:knowlton
ID: 39216520
Thanks!
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

Suggested Solutions

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

929 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

13 Experts available now in Live!

Get 1:1 Help Now