Compare item in dropdownlist with string

Discussion in 'ASP.NET / ASP.NET Core' started by calvin, Jul 15, 2004.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I want to validate all items in dropdownlist with string/label.
    So, I try to write like this:

    If dropdownlist.Items.<u>Contains(label.text)</u> Then
    .
    .
    .

    But I get an error of "Value of String cannot be converted to System.Web.UI.WebControls.ListItem"

    Does anybody know how to convert it??

    Thank you for any help.
    Calvin
     
  2. In fact I want to know does the dropdownlist contain the value same as label.text

    For example If the label.text = "Hello world", check the dropdownlist contain the item "Hello world" or not.


    Calvin
     
  3. .FindByText is, I think, what you're looking for. This function returns null (Nothing) if it doesn't find an item.

    I'll try this in VB, but don't yell at me if the syntax is wrong. I'm not sure if != is "not Equal" in VB...:)

     
  4. Bruce

    Bruce DiscountASP.NET Staff

    Contains method is expecting System.Web.UI.WebControls.ListItem as the input parameter

    In order to get the item name, you'll have to look at

    DropDownList.Items(0).ToString

    You may need to loop through it.


    quote:Originally posted by calvin

    I want to validate all items in dropdownlist with string/label.
    So, I try to write like this:

    If dropdownlist.Items.<u>Contains(label.text)</u> Then
    .
    .
    .

    But I get an error of "Value of String cannot be converted to System.Web.UI.WebControls.ListItem"

    Does anybody know how to convert it??

    Thank you for any help.
    Calvin
    </blockquote id="quote"></font id="quote">
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page