I am loading a ListBox OnSelectedChange of DropDownlist. If I select a 3rd value from the ListBox, it always returns 0. What could be wrong? I appreciate any help. Thank you. Here is my code.
<asp:DropDownList ID="dropdown1" runat="server" Width="300" OnSelectedIndexChanged="onChange"
AutoPostBack="true">
<asp:ListBox ID="list1" runat="server" Width="300" Rows="12" CausesValidation="true"/>
protected void OnChange(object sender, EventArgs e)
{
LoadListBox();
}
void LoadListBox()
{
list1.Items.Clear();
System.Data.DataTable rows = new System.Data.DataTable();
rows = DAL.GetValues();
foreach (System.Data.DataRow row1 in rows.Rows) {
list1.Items.Add(new ListItem(row1["measurement"].ToString().Trim(), row1["measurement"].ToString()));
}
}
when you change the listbox value to three this will fire the onchange event
In your onchange event you should could check the value to see what the value has changed to.
in your code you are reloading the list of values in the onchanged event which will reset the selected value back to zero.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With