DropDownList SelectedIndexChanged event not firing within GridView HeaderTemplate
Asked Answered
I

2

3

I am working on a job board website and specifically the job search page at the moment. I am returning the jobs found into a DataBound GridView (namely gvwJobs), and within the HeaderTemplate I have a DropDownList named ddlSortDirection which specifies the direction in which the sorting is performed:

<asp:DropDownList runat="server" ID="ddlSortDirection" AutoPostBack="true" OnSelectedIndexChanged="ddlSortDirection_SelectedIndexChanged">

    <asp:ListItem Value="DESC">DOWN</asp:ListItem>
    <asp:ListItem Value="ASC">UP</asp:ListItem>

</asp:DropDownList>

As you can see, I have ensured that AutoPostBack is on. I have also created a custom event handler on the GridView's DataBound event as so:

Protected Sub gvwJobs_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvwJobs.RowDataBound

    If e.Row.RowType = DataControlRowType.Header Then

                ddlSortDirection.AutoPostBack = True
                AddHandler ddlSortDirection.SelectedIndexChanged, AddressOf ddlSortDirection_SelectedIndexChanged


     End If

End Sub

I am finding that the ddlSortDirection_SelectedIndexChanged SubProcedure is not called when the selection is changed in ddlSortDirection. I can see that a PostBack occurs, but the method is definitely not called. What I have tried doing is creating a similar DropDownList outside of the GridView and that successfully triggered the SelectedIndexChanged event without even having a custom event handler!

Please could you help me to achieve my goal of having a DropDownList firing the SelectedIndexChanged event when within a HeaderTemplate of a GridView?

Industrialize answered 21/1, 2010 at 12:36 Comment(0)
F
1

set the EnableViewState of that GridView to false

Flouncing answered 28/11, 2011 at 19:56 Comment(0)
E
-1

set runat="server" on DropDownList

Eg:

<asp:DropDownList ID="ddlSortDirection" runat="server" AutoPostBack="True" 
            onselectedindexchanged="ddlSortDirection_SelectedIndexChanged">
</asp:DropDownList>
Ember answered 7/1, 2013 at 5:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.