E
et
How can I add a blank item to a drop down list so that it is the first item
in the list?
My drop down list is bound to a datareader, and if I add a blank item first
as follows --
ddl.Items.Add(New ListItem(" ", 0)) -- then binding erases the blank item.
Or maybe there is another way to solve my problem. An item in the drop down
list is automatically selected by FindByValue:
ddl.SelectedIndex =
ddl.Items.IndexOf(ddl.Items.FindByValue(Session("ID")))
If the above does not find a match, the SelectedIndex defaults to 0, and
hence the first item is selected. Since the first item contains a valid
value, I end up with a false result. I can't have it select the last item
if the SelectedIndex defaults to 0, because then when the first item should
be selected correctly, it ends up blank, again erroneously.
Hope that makes sense. Thanks for your help.
in the list?
My drop down list is bound to a datareader, and if I add a blank item first
as follows --
ddl.Items.Add(New ListItem(" ", 0)) -- then binding erases the blank item.
Or maybe there is another way to solve my problem. An item in the drop down
list is automatically selected by FindByValue:
ddl.SelectedIndex =
ddl.Items.IndexOf(ddl.Items.FindByValue(Session("ID")))
If the above does not find a match, the SelectedIndex defaults to 0, and
hence the first item is selected. Since the first item contains a valid
value, I end up with a false result. I can't have it select the last item
if the SelectedIndex defaults to 0, because then when the first item should
be selected correctly, it ends up blank, again erroneously.
Hope that makes sense. Thanks for your help.