Solved

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

Posted on 2013-05-29
3
726 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 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

10 Experts available now in Live!

Get 1:1 Help Now