This is just how most (all maybe?) browsers work. If you create a static
html file and put a <selectin it with some options, the first one is
selected by default in every browser I've used. According to W3C, this is
up to the browser to determine what the right thing to do is.
http://www.w3.org/TR/html4/interact/forms.html#h-17.6 "If no OPTION element
has the selected attribute set, user agent behavior for choosing which
option is initially selected is undefined."
Perhaps this will be a satisfactory option:
<asp:DropDownList ID="ddl" runat="server" DataValueField="ID"
DataTextField="Display" AppendDataBoundItems="true">
<asp:ListItem Value="">Select an option</asp:ListItem>
</asp:DropDownList>
Note the AppendDataBoundItems attribute.
Ray at work
<am******@gmail.comwrote in message
news:11*********************@u32g2000prd.googlegro ups.com...
>I have a simple webform that has a listbox that I bind to a dataview
at designtime. This provides an optional selection for the user so I
wanted to have no default value selected. So on the Page_Load event,
I set the selectedIndex to -1. However, when I run the page, the
default value is still 0, which forces the first item to be
automatically selected. I tried a bunch of things. I tried setting
it to 0, then -1. I tried to call ClearSelection() then set it to -1,
but no avail. This is a listbox, for crying out loud! This ought to
be simple, but is not.
Need help.