DropDownList not allowing SelectedIndex = -1

G

Guest

Ok I'll start out with I found:

http://support.microsoft.com/kb/327244/
BUG: ComboBox Does Not Clear When You Set SelectedIndex to -1

Ok so in HTML you can have:

<select id="MyList">
<option value="1">1
<option value="2">2
<option value="3">3
</select>

And in javascript you can set MyList.selectedIndex = -1 which will display
the dropdown with nothing selected.

I'm using .NET 1.1 and this doesn't work? WHY? Why has there been no fix
for this that I can find. The ListBox control allows the SelectedIndex = -1
and shows the list with nothing selected but the Dropdownlist control reverts
to SelectedIndex = 0 when you set it to -1 and always shows the first item
selected.

Yes I know I could add a blank item to the list but that's not the point.
Microsoft Obviously knows there a bug but hasn't fixed it. Even the work
arounds do not work.

Anyone have any comments or solutions about this.
 
B

Bruce Barker

there is no html solution for this as the selectedItem is not exposed.
client script is required, probably why asp.net does not support it.

<asp:listbox id=listBox1 runat=server>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:listbox>
<script>
document.getElementById('<%=listBox1.ClientID%>').selectedIndex=<%=listBox1.selectedIndex%>;
</script>


-- bruce (sqlwork.com)
 
G

Guest

Your wrong sorry to tell you.

For a list box SelectedIndex = -1 works fine as expected but for a
dropdownlist it doesn't however it should and according to the bug report
from Microsoft they knew it was a problem in .NET 1.0 and had a workaround
but in 1.1 the workaround doesn't work and the bug is still there.
 

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,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top