ASP.Net DropDownList OnSelectedIndexChange Not Shooting

I have the following DropDownList control:

<asp:label runat="server" text="Filter by state: "></asp:label> <asp:dropdownlist runat="server" id="filterbystate" OnSelectedIndexChanged="FilterByState"> <asp:ListItem value="all" selected="True">All</asp:ListItem> <asp:ListItem value="ca" selected="False">California</asp:ListItem> <asp:ListItem value="co" selected="False">Colorado</asp:ListItem> <asp:ListItem value="id" selected="False">Idaho</asp:ListItem> <asp:ListItem value="ut" selected="False">Utah</asp:ListItem> </asp:dropdownlist> 

Here is a way:

 protected void FilterByState(object sender, EventArgs e) { var value = e; } 

For some reason, the method does not work. I choose a different value and nothing happens. What I'm trying to do is reload the page by passing a status value so that I can filter the results.

What am I doing wrong?

+7
source share
4 answers

Set AutoPostBack=True as an attribute of your DDL and it will automatically post the selected index change event

+22
source

Add this to the aspx drop-down list, this will cause a request to be sent to the server, and your event will fire.

 AutoPostBack="true" 
+2
source

You just need to set AutoPostBack = True

From the ListControl.AutoPostBack property;

Gets or sets a value indicating whether the postback to the server will automatically occur when the user changes the list selection.

+2
source

AutoPostBack="true" and

record page load event

 if (!IsPostBack) { DDL_Designation_Bind(); } 

// Because the autopostback property is fire load event, and then our dropdownlist re-binds and the index is always 0, so Not Rebinding dropdownlist

+1
source

All Articles