Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-05-29
3
Medium Priority
?
918 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:Tom Knowlton
[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
3 Comments
 
LVL 19

Accepted Solution

by:
Manoj Patil earned 1000 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 1000 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:Tom Knowlton
ID: 39216520
Thanks!
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

722 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