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 trying add list items ddl2 on ddl1.selectedindexchanged based on 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"))  protected sub ddl1_selectedindexchanged(byval sender object, byval e eventargs) handles ddl1.selectedindexchanged     ddl2.items.clear()         if (ddl1.selectedindex = 0)  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")) end if end sub 

on submit unable retain selected value of ddl2.

please me suggestions. have tried using hidden values, still unsuccessful.

note: using user control.

dont forget make autopostback property of ddl1 true.

put in ddl1 select index changed

if ddl1.selectedvalue = "test1"     ddl2.items.add("one") elseif ddl1.selectedvalue = "test2"     ddl2.items.add("two") else     ddl2.items.add("three") end if 

put in button click

label1.text = "first : " + ddl1.selectedvalue.tostring() + "second :" + ddl2.selectedvalue.tostring() 

i tried , works.alter according requirement


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -