DropownList Not workin'
-
I have a
DropdownList
I bind data to it at runtime. It alls well but when I select some value and click on a button, I need to pass the selected value to the next page in a query string but the first value reagardless of what I select is passed like,btn_Click(..)
{
Response.Redirect("XYZ.aspx?ID=" + Dropdwn1.SelectedValue.ToString())
}But the first value, which is 0, is passed no mater what I select I also tried a post back ie. I made the Dropdown to AutoPostBack=True and
Private Sub drpdwn1_SelectedIndexChanged(..)
Response.Write(drpdwn1.SelectedValue.ToString())
End SubBut still the first value is writter not the one I select Help _____________________________________________________ Yea! I could be wrong...
-
I have a
DropdownList
I bind data to it at runtime. It alls well but when I select some value and click on a button, I need to pass the selected value to the next page in a query string but the first value reagardless of what I select is passed like,btn_Click(..)
{
Response.Redirect("XYZ.aspx?ID=" + Dropdwn1.SelectedValue.ToString())
}But the first value, which is 0, is passed no mater what I select I also tried a post back ie. I made the Dropdown to AutoPostBack=True and
Private Sub drpdwn1_SelectedIndexChanged(..)
Response.Write(drpdwn1.SelectedValue.ToString())
End SubBut still the first value is writter not the one I select Help _____________________________________________________ Yea! I could be wrong...
DropDownList in ASP.NET has a bug. If there are 2 or more items with the same value property the SelectedIndex property is not returning the index of the focued item, as it should, but the index of the first item in the list which has got the same value property as the value of the focused one. For example if item 2 has value="a" and item 8 has got also value="a" then when you select item 8 the following code: DDL.items[DDL.SelectedItem].text is showing the text of item 2 !. Check if the same happens with the property SelectedValue.
-
DropDownList in ASP.NET has a bug. If there are 2 or more items with the same value property the SelectedIndex property is not returning the index of the focued item, as it should, but the index of the first item in the list which has got the same value property as the value of the focused one. For example if item 2 has value="a" and item 8 has got also value="a" then when you select item 8 the following code: DDL.items[DDL.SelectedItem].text is showing the text of item 2 !. Check if the same happens with the property SelectedValue.
Hello, No I do not have the same values for even 2 of DropdownList Values. No other value, other than the 1st has the value=0, all others are strings like 'ID-02342' etc. But the problem still remains _____________________________________________________ Yea! I could be wrong...
-
Hello, No I do not have the same values for even 2 of DropdownList Values. No other value, other than the 1st has the value=0, all others are strings like 'ID-02342' etc. But the problem still remains _____________________________________________________ Yea! I could be wrong...
I think may be you have an initialization in Page_Load event that's executed everytime there's a post. That happened to me before, for example:
private sub Page_Load(x as object, x as eventargs) binddropdownmethod() end sub
change it to:private sub Page_Load(x as object, x as eventargs) if not ispostback then binddropdownmethod() end if end sub
Look at it, I'm almost sure that somewhere in your code, the dropdown must be binding to data before going into the button's event, and this resets the selection done. daniero