Note that there are some explanatory texts on larger screens.

plurals
  1. POListbox Returns Empty String on SelectedIndexChanged Event
    text
    copied!<p>The above error occurs on a SelectedIndexChanged click event on a listbox.</p> <p>in debug the value returned is "", however when you look at the webpage source code there are definitely values.</p> <p>Here's my listbox:</p> <pre><code>&lt;asp:ListBox ID="lstBxMyList" runat="server" CssClass="binorderlst1" DataTextField="myName" DataValueField="myID" OnSelectedIndexChanged ="lstBxMyList_SelectedIndexChanged" AutoPostBack="true" Rows="10"&gt; &lt;/asp:ListBox&gt; </code></pre> <p>Here's the event:</p> <pre><code>protected void lstBxMyList_SelectedIndexChanged(object sender, EventArgs e) { myID = Convert.ToInt32(lstBxSiteList.SelectedValue.ToString()); ... rest of code } </code></pre> <p>For completeness here's the data binding:</p> <pre><code>private void BindLstBxMyList(int myOtherID) { DataTable dt = new DataTable(); SqlConnection conn; SqlCommand comm; using (conn = new SqlConnection(aSHconns.aconn)) { comm = new SqlCommand("myStoredProc", conn); comm.CommandType = CommandType.StoredProcedure; comm.Parameters.Add(new SqlParameter("@myOtherID", SqlDbType.Int)); comm.Parameters["@myOtherID"].Value = myOtherID; SqlDataAdapter sqlDa = new SqlDataAdapter(comm); try { conn.Open(); sqlDa.Fill(dt); if (dt.Rows.Count &gt; 0) { lstBxMyList.DataSource = dt; lstBxMyList.DataTextField = "myName"; lstBxMyList.DataValueField = "myID"; lstBxMyList.DataBind(); } } finally { conn.Close(); } } } </code></pre> <p>If I revert back to a SqlDataSource the listbox returns values. Bt I need to repopulate the list, so I need the code behind databind (unless there is a better way of course)</p> <p>So why is the listbox selected value returning an empty string? Any help would be gratefully received.</p>
 

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