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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top