7

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?

James Wilson
  • 5,074
  • 16
  • 63
  • 122

4 Answers4

25

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

Josh E
  • 7,390
  • 2
  • 32
  • 44
2

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"
DotNetUser
  • 6,494
  • 1
  • 25
  • 27
2

You just need to set AutoPostBack = True

From ListControl.AutoPostBack property;

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

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
1

AutoPostBack="true" and

write page load event

if (!IsPostBack)
{
   DDL_Designation_Bind();   
}

// Because autopostback properties fire load event then our dropdownlist rebind and always selected index 0 so Not Rebinding dropDownlist

Manish Jesani
  • 1,339
  • 5
  • 20
  • 36
sunil sahu
  • 11
  • 1