Note that there are some explanatory texts on larger screens.

plurals
  1. PODropDownList SelectedIndexChanged not firing (yes, AutoPostBack="true")
    primarykey
    data
    text
    <p>I hate to put another one of these up here, but the 20 other questions of this type have been answered with "set <code>AutoPostBack="true"</code>", which I've already done. I believe my problem is more in the way I'm setting the items in the DropDownList, but I'm new at ASP.NET, so I'm not sure what the proper solution is.</p> <p>Here's my control:</p> <pre><code>&lt;asp:DropDownList ID="DrpProduct" CssClass="input-xxlarge" runat="server" AutoPostBack="true" EnableViewState="true" OnSelectedIndexChanged="DrpProduct_SelectedIndexChanged" ViewStateMode="Enabled" /&gt; </code></pre> <p>And here's where I'm setting it in the code-behind of the page: </p> <pre><code>protected void Page_Init(object sender, EventArgs e) { Repository = new ProductRepository(); Products = Repository.List(); if (Products.Any()) foreach (Product product in Products) { DrpProduct.Items.Add(new ListItem(product.Name, product.Name)); } } </code></pre> <p>And finally my listener:</p> <pre><code>protected void DrpProduct_SelectedIndexChanged(object sender, EventArgs eArgs) { //code omitted. I have a breakpoint here that never gets hit anyways. } </code></pre> <p>They render and display properly, but the OnSelectedIndexChanged event is not being hit when I use the dropdown. I've read that adding items to the dropdown this way can be problematic if not done at the proper stage of the page's lifecycle, but I've tried it on multiple other stages to no effect. I'm doing it this way (rather than data bound objects, etc) for a specific reason, so would like to make this code work for me. </p> <p><strong>EDIT:</strong> By request, here is my ProductRepository code:</p> <pre><code>public class ProductRepository { private IList&lt;Product&gt; Products { get; set; } public ProductRepository() { Products = new List&lt;Product&gt; { new Product("Grand Theft Auto V", "A video game that lets you kill hookers.", 59.99m), new Product("Fallout 4", "lol u wish", 99.99m), new Product("XCOM: Enemy Unknown", "Probably one of the better games you'll ever play.", 39.99m), new Product("The Bureau: XCOM Declassified", "The game NO ONE asked for. Or wanted.", 59.99m), new Product("Rome 2: Total War", "There'd better be phalanxes.", 59.99m) }; } public IList&lt;Product&gt; List() { return Products; } } </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.
 

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