Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>li.Attributes.Add("onselectedindexchanged","selectedIndexChanged"); </code></pre> <p>Adds a client-side HTML attribute. The selectedIndexChanged method you've shown here is a server side method. You either need to add an auto-post-back to your control, and a server-side event handler to the control to make it call your C# function on the server, or make a client-side JavaScript function to handle the client-side event.</p> <p>edit---</p> <p>When the page is posted back to the server, the control ceases to exist. The Page is a new isntance, which hasn't had the listbox added to its controls collection. The event IS being called when auto-postback is true, but the control doesn't exist in the server's Page object, and if you remove the If Page.IsPostBack block, the control is re-created, and so the control is not the one whose event was raised, and that control still doesn't exist.</p> <p>Whats the actual aim of this control? Is it just to provide a master-details thing?</p> <p>edit 2---</p> <p>Created solution for you that works:</p> <p>Page:</p> <pre><code>&lt;asp:ListBox ID="ListBox1" runat="server" AutoPostBack="true" Visible="false" OnSelectedIndexChanged="ListBox1_SelectedIndexChanged"&gt;&lt;/asp:ListBox&gt; &lt;br /&gt; &lt;asp:ListBox ID="ListBox2" runat="server" Visible="false"&gt;&lt;/asp:ListBox&gt; </code></pre> <p>Codebehind:</p> <pre><code>private List&lt;string&gt; myList = new List&lt;string&gt; { "Serkan", "Kadir" }; private List&lt;string&gt; mySecondList = new List&lt;string&gt; { "Istanbul", "Ankara" }; protected void Page_Load(object sender, System.EventArgs e) { if (!Page.IsPostBack) { if (myList.Count &gt; 0) { ListBox1.DataSource = myList; ListBox1.DataBind(); ListBox1.Visible = true; } } } protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e) { ListBox2.DataSource = mySecondList; ListBox2.DataBind(); ListBox2.Visible = true; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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