Listbox.SelectedIndex command doesn't update!

J

jeffd

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!
 
C

Chris Westbrook

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.
 
J

Jeff Dugger

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.
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top