Monday, 19 August 2013

ASP.NET: dropdownlist not retaining values on submit

ASP.NET: dropdownlist not retaining values on submit

<asp:DropDownList ID="ddl1" runat="server" AutoPostBack="True" Width="110px">
<asp:ListItem>Test1</asp:ListItem>
<asp:ListItem>Test2</asp:ListItem>
<asp:ListItem>Test3</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddl2" runat="server" Width="110px">
</asp:DropDownList>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" />
I am trying to add list items to ddl2 on ddl1.SelectedIndexChanged based
on the selected index.
ddl2.Items.Insert(0, New ListItem("Please Select", "-1"))
ddl2.Items.Insert(1, New ListItem("value2", "1"))
ddl2.Items.Insert(2, New ListItem("value3", "2"))
On submit i am unable to retain the selected value of ddl2.
Please provide me a working solution in VB.NET. I have tried using hidden
values, still unsuccessful.
Note: I am using an user control.
Thank You.

No comments:

Post a Comment