Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding DropDownList index by text

Tags:

asp.net

I have a populated DropDownList. How do I find the index whose Text value is "x"?

like image 696
spud Avatar asked Feb 16 '11 09:02

spud


People also ask

How to get index value of DropDownList in ASP net?

If you want to get value on server side you can follow this. ddlsample. SelectedIndex = ddlsample. Items.

What is the difference between listbox and DropDownList?

The following terms are important to understand as you read this article: A standard list box is a box containing a list of multiple items, with multiple items visible. A drop-down list is a list in which the selected item is always visible, and the others are visible on demand by clicking a drop-down button.


1 Answers

If you want to get value on server side you can follow this.

ddlsample.SelectedIndex = ddlsample.Items.IndexOf(ddlsample.Items.FindByValue("x")); // If you want to find text by value field.
ddlsample.SelectedIndex = ddlsample.Items.IndexOf(ddlsample.Items.FindByText("x"));// If you want to find text by TextField.
like image 193
ashish.chotalia Avatar answered Sep 19 '22 18:09

ashish.chotalia