ListBox control

Discussion in 'ASP .Net' started by =?Utf-8?B?SXJmYW4gQWtyYW0=?=, Feb 14, 2005.

  1. Hi Guys,

    I have non-unique values in my ListBox control, so whenever I do something
    like
    if (myList.SelectedIndex == 2) I get wrong results, as it picks out the
    wrong index. How can I ammend this problem, so that I get the selected index,
    i.e. the exact index selected.

    Thanks,

    I.A
    =?Utf-8?B?SXJmYW4gQWtyYW0=?=, Feb 14, 2005
    #1
    1. Advertising

  2. Irfan,

    you can try to use the SelectedValue property if you know the value you have
    to compare to. For example if you have a listbox with Red, Green, Blue:

    if (myList.SelectedValue == "Red")
    // [...]

    Hope that helps!

    Regards,
    Michael

    "Irfan Akram" <> schrieb im Newsbeitrag
    news:...
    > Hi Guys,
    >
    > I have non-unique values in my ListBox control, so whenever I do something
    > like
    > if (myList.SelectedIndex == 2) I get wrong results, as it picks out the
    > wrong index. How can I ammend this problem, so that I get the selected

    index,
    > i.e. the exact index selected.
    >
    > Thanks,
    >
    > I.A
    Michael Groeger, Feb 15, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. blenderdude
    Replies:
    0
    Views:
    978
    blenderdude
    Aug 3, 2003
  2. DC Gringo
    Replies:
    0
    Views:
    398
    DC Gringo
    Apr 6, 2004
  3. kent
    Replies:
    1
    Views:
    875
    Andrew de la Harpe
    May 3, 2004
  4. Simon Prince
    Replies:
    2
    Views:
    3,323
    =?Utf-8?B?TWljaGFlbCBUYXlsb3I=?=
    Oct 19, 2004
  5. Chris Kettenbach

    Listbox selection to populate another listbox?

    Chris Kettenbach, Jun 15, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    1,645
    Chris Kettenbach
    Jun 16, 2005
Loading...

Share This Page