Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET Webforms cascading dropdown Lists - second list's selected value resets on postback
    text
    copied!<p>My problem's probably trivial, but I can't remind myself how to do that. I have 2 dropdown lists:</p> <pre><code>&lt;span&gt; &lt;asp:DropDownList ID="DDLEditWydzial" runat="server" DataSourceID="SqlListaWydzialow" AutoPostBack="true" DataTextField="NazwaWydzialu" DataValueField="ident" OnSelectedIndexChanged="OnWydzialChanged" EnableViewState="true"&gt; &lt;/asp:DropDownList&gt; &lt;/span&gt; &lt;span&gt; &lt;span style="font-size: 8pt; font-family: Arial CE"&gt; &lt;asp:DropDownList ID="DDLEditSale" runat="server" EnableViewState="true" AutoPostBack="true"&gt; &lt;/asp:DropDownList&gt; &lt;/span&gt; &lt;/span&gt; </code></pre> <p>First one is filled with via <code>SqlDataSource</code>, second is filled depending on choice in previous. This is done by an event handler:</p> <pre><code>protected void OnWydzialChanged(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["sworConnectionString"].ConnectionString); conn.Open(); using (conn) { SqlCommand command = new SqlCommand("SELECT '-- wybierz salę --' as numer, -1 as ident UNION " + "SELECT 'Sala ' + s.numer as numer, s.ident FROM sala s, sala_wydzial sw where s.czyus=0 and sw.id_wydzial=" + DDLEditWydzial.SelectedValue + " and sw.id_sala = s.ident", conn); SqlDataReader salaReader = command.ExecuteReader(); DDLEditSale.AppendDataBoundItems = true; DDLEditSale.DataSource = salaReader; DDLEditSale.DataTextField = "numer"; DDLEditSale.DataValueField = "ident"; DDLEditSale.DataBind(); conn.Close(); conn.Dispose(); } } </code></pre> <p>Then, when I chose value from 2nd list, comes postback and after a refresh list contains with data, but nothing in 2nd DDL is selected. I've checked Page_Load and DDLEditSale is empty then.</p> <p>Any ideas?:)</p> <p>EDIT: OnInit and InitializeComponent code (it's generated by ZedGraph):</p> <pre><code>override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// &lt;summary&gt; /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// &lt;/summary&gt; private void InitializeComponent() { this.ZedGraphWeb1.RenderGraph += new ZedGraph.Web.ZedGraphWebControlEventHandler(this.OnRenderGraph); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload