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 the method:
protected void FilterByState(object sender, EventArgs e)
{
var value = e;
}
The method will not fire for some reason. I select a different value and nothing happens. What I am trying to do is reload the page passing in the state value so I can filter the results by it.
What am I doing wrong?
When an item is changed in ASP.Net DropDownList, the following OnSelectedIndexChanged event handler is executed. Inside the event handler, the selected Text and Value of the DropDownList Selected Item is fetched and displayed using JavaScript Alert message box.
The example uses the SelectedIndexChanged event to determine when the selected item in the ListBox is changed. The example code then reads the text of the item using the SelectedItem property and calls the FindString method on a different ListBox using the text returned by SelectedItem in the first ListBox.
Set AutoPostBack=True
as an attribute of your DDL and it will automatically post back the selected index change event
Add this to dropdown list aspx it will cause a request to be send to the server and your event will be fired.
AutoPostBack="true"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With