Setting listbox.SelectedValue gives an error as the listbox seems to be empty when the call is made.
Setting listbox.SelectedIndex seems to work, but I cannot use it as I do not know the index value that I need.
How can I set the initial values successfully?Just discovered the DataBound event, which triggers when the data has been loaded into the listbox.
I now set my initial value in that event and everything works as planned.
do you know the value of the item you want to select? if so, you can search the DDL by value:
ddl.SelectedItemIndex = ddl.Items.IndexOf(ddl.Items.FindByValue("value");
FYI...EasyListBox makes this (and many other things) about ten times less painful. You select items by setting myList.SelectedValue... you don't lose your selection if you databind again (or even if you turn ViewState off)... and then there's the really good stuff.
Just another two cents...
0 comments:
Post a Comment