Selecting some values in DeropDownList

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

Hello.

I have DeropDownList control on my page and want to select some value by
SelectedValue, but before selecting I want to ensure that the value exists
in DeropDownList control's items.
How can I check it?
P.S. I must check only by value not by text.

Thank you.
 
There are some built in methods for this.
DropDownList.Items.FindByValue()
DropDownList.Items.FindByText()

//sample.
DropDownList ddl = new DropDownList();

ListItem foundItem = ddl.Items.FindByValue( "ValueToLookFor" );
if ( foundItem != null )
{
//value was found!
}

bill
 
Back
Top