DropDownListBox Bug.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I think we have some bug in dropdownlistbox server control. Following are the values.

<asp:DropDownList id="DropDownList1" runat="server">
<asp:ListItem value="46">INR</asp:ListItem>
<asp:ListItem value="2">USE</asp:ListItem>
<asp:ListItem value="1">USD</asp:ListItem>
<asp:ListItem value="1">URO</asp:ListItem>
<asp:ListItem value="29">SND</asp:ListItem>
<asp:ListItem value="46.09">INP</asp:ListItem>
<asp:ListItem value="47">IDR</asp:ListItem>
<asp:ListItem value=".7">EURO</asp:ListItem>
<asp:ListItem value="70">EUR</asp:ListItem>
</asp:DropDownList>

Now when ever you select USD or URO option it always returns selectindex as "2". This is very strange and seems to be like a bug.

Can someone tell me wheather its know bug and if so what is the way around to solve this.

Regards,
 
Check out whether you are binding your datagrid or setting selected value for dropdownlist in page_load without checking for ispostback().

--
Saravana
Microsoft MVP - ASP.NET
www.extremeexperts.com



<Jignesh> wrote in message I think we have some bug in dropdownlistbox server control. Following are the values.

<asp:DropDownList id="DropDownList1" runat="server">
<asp:ListItem value="46">INR</asp:ListItem>
<asp:ListItem value="2">USE</asp:ListItem>
<asp:ListItem value="1">USD</asp:ListItem>
<asp:ListItem value="1">URO</asp:ListItem>
<asp:ListItem value="29">SND</asp:ListItem>
<asp:ListItem value="46.09">INP</asp:ListItem>
<asp:ListItem value="47">IDR</asp:ListItem>
<asp:ListItem value=".7">EURO</asp:ListItem>
<asp:ListItem value="70">EUR</asp:ListItem>
</asp:DropDownList>

Now when ever you select USD or URO option it always returns selectindex as "2". This is very strange and seems to be like a bug.

Can someone tell me wheather its know bug and if so what is the way around to solve this.

Regards,
 
I think we have some bug in dropdownlistbox server control. Following are the values.

<asp:DropDownList id="DropDownList1" runat="server">
<asp:ListItem value="46">INR</asp:ListItem>
<asp:ListItem value="2">USE</asp:ListItem>
<asp:ListItem value="1">USD</asp:ListItem>
<asp:ListItem value="1">URO</asp:ListItem>
<asp:ListItem value="29">SND</asp:ListItem>
<asp:ListItem value="46.09">INP</asp:ListItem>
<asp:ListItem value="47">IDR</asp:ListItem>
<asp:ListItem value=".7">EURO</asp:ListItem>
<asp:ListItem value="70">EUR</asp:ListItem>
</asp:DropDownList>

Now when ever you select USD or URO option it always returns selectindex as
"2". This is very strange and seems to be like a bug.
Can someone tell me wheather its know bug and if so what is the way around to solve this.

Regards,

It's logical, because it's the value that is posted back. ASP.NET
looks it up and returns the first index that matches this value.
I guess that any other server-side script would give you the same problem.

I would try to make the values different (e.g. "1" and "1.0")
 
No Saravana, Values are hardcoded. there is noting in page_load event.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Write(Me.DropDownList1.SelectedIndex.ToString())
Response.Write(Me.DropDownList1.SelectedItem.Text)
End Sub

Check out whether you are binding your datagrid or setting selected value for dropdownlist in page_load without checking for ispostback().

--
Saravana
Microsoft MVP - ASP.NET
www.extremeexperts.com



<Jignesh> wrote in message I think we have some bug in dropdownlistbox server control. Following are the values.

<asp:DropDownList id="DropDownList1" runat="server">
<asp:ListItem value="46">INR</asp:ListItem>
<asp:ListItem value="2">USE</asp:ListItem>
<asp:ListItem value="1">USD</asp:ListItem>
<asp:ListItem value="1">URO</asp:ListItem>
<asp:ListItem value="29">SND</asp:ListItem>
<asp:ListItem value="46.09">INP</asp:ListItem>
<asp:ListItem value="47">IDR</asp:ListItem>
<asp:ListItem value=".7">EURO</asp:ListItem>
<asp:ListItem value="70">EUR</asp:ListItem>
</asp:DropDownList>

Now when ever you select USD or URO option it always returns selectindex as "2". This is very strange and seems to be like a bug.

Can someone tell me wheather its know bug and if so what is the way around to solve this.

Regards,
 
No its not a bug. You have duplicate values in the drop down list.

Do you know how a regular HTML select control works? Which is what the dropdownlist control gets drawn as in the browser. When a postback happens the name of the control and the value is sent back from an HTML form. In this example, if you pick USD or URO, it would be something like DropDownList1=1. Notice its not the index that gets sent back but the value. This is how HTML works. ASP.NET has no way of knowing which one you meant and it picks the first one it finds with the identical value.


<Jignesh> wrote in message I think we have some bug in dropdownlistbox server control. Following are the values.

<asp:DropDownList id="DropDownList1" runat="server">
<asp:ListItem value="46">INR</asp:ListItem>
<asp:ListItem value="2">USE</asp:ListItem>
<asp:ListItem value="1">USD</asp:ListItem>
<asp:ListItem value="1">URO</asp:ListItem>
<asp:ListItem value="29">SND</asp:ListItem>
<asp:ListItem value="46.09">INP</asp:ListItem>
<asp:ListItem value="47">IDR</asp:ListItem>
<asp:ListItem value=".7">EURO</asp:ListItem>
<asp:ListItem value="70">EUR</asp:ListItem>
</asp:DropDownList>

Now when ever you select USD or URO option it always returns selectindex as "2". This is very strange and seems to be like a bug.

Can someone tell me wheather its know bug and if so what is the way around to solve this.

Regards,
 
Back
Top