Listbox.SelectedIndex command doesn't update!

Discussion in 'ASP .Net Web Controls' started by jeffd, Aug 27, 2003.

  1. jeffd

    jeffd Guest

    I have a listbox control which is populated from a database via a
    handler of it's onload event. After (or before, I've tried both) I
    bind the dataset to the listbox, I attempt to use

    mylistbox.Items.FindByValue("myvalue").Selected = True

    to match a previously fetched database value. The code executes
    without a problem, but on the aspx page the listbox doesn't have a
    selected value at all! Is there some sort of update command or
    something I need to call on the listbox? I've also tried just using a
    static mylistbox.selectedindex = x command just to test it, but that
    doesn't show up either!
    jeffd, Aug 27, 2003
    #1
    1. Advertising

  2. (jeffd) wrote in message news:<>...
    > I have a listbox control which is populated from a database via a
    > handler of it's onload event. After (or before, I've tried both) I
    > bind the dataset to the listbox, I attempt to use
    >
    > mylistbox.Items.FindByValue("myvalue").Selected = True
    >
    > to match a previously fetched database value. The code executes
    > without a problem, but on the aspx page the listbox doesn't have a
    > selected value at all! Is there some sort of update command or
    > something I need to call on the listbox? I've also tried just using a
    > static mylistbox.selectedindex = x command just to test it, but that
    > doesn't show up either!


    I am running into something similar, although it is also complicated
    by nested repeaters. One thing we tried was to set the selectedIndex:

    dim itemToSelect = mylistbox.Items.FindByValue("myvalue")
    if not itemToSelect is nothing then
    mylistbox.selectedindex = mylistbox.items.indexof(itemToSelect)
    end if

    Now...that didn't actually work for us, but following through in the
    debugger it looked like it would, and I think our problems are still
    related to the nested repeater. So, anyway...something to try.

    Chris W.
    Chris Westbrook, Aug 27, 2003
    #2
    1. Advertising

  3. jeffd

    Jeff Dugger Guest

    Thanks Chris! I also have my ListBox control nested inside a DataList
    Control. I am having no luck updating the Selected Item
    programmatically and having it show up on the resulting HTML page. This
    seems like it should be something simple and fairly common, if I figure
    it out I'll be sure to post a solution.

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Jeff Dugger, Aug 27, 2003
    #3
    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. John Giblin

    Asp:ListBox and selectedindex

    John Giblin, Nov 26, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    1,094
    John Giblin
    Nov 26, 2003
  2. S. Justin Gengo

    ListBox SelectedIndex is always -1

    S. Justin Gengo, Feb 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,750
  3. =?Utf-8?B?TGll?=
    Replies:
    5
    Views:
    671
    =?Utf-8?B?TGll?=
    Dec 14, 2004
  4. =?Utf-8?B?Q2FybG8gTWFyY2hlc29uaQ==?=

    ListBox not returning correct SelectedIndex

    =?Utf-8?B?Q2FybG8gTWFyY2hlc29uaQ==?=, Feb 4, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    4,263
    Karl Seguin
    Feb 4, 2005
  5. ThunderMusic
    Replies:
    6
    Views:
    1,796
    ThunderMusic
    Dec 12, 2005
Loading...

Share This Page