Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 958
  • Last Modified:

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

(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
Tom Knowlton
Asked:
Tom Knowlton
2 Solutions
 
Manoj PatilSr. Software EngineerCommented:
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
 
Naman GoelCommented:
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
 
Tom KnowltonWeb developerAuthor Commented:
Thanks!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now