开发者

DropDownList SelectedIndexChanged event not firing within GridView HeaderTemplate

开发者 https://www.devze.com 2022-12-17 11:03 出处:网络
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

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
开发者_如何学C                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?


set the EnableViewState of that GridView to false


set runat="server" on DropDownList

Eg:

<asp:DropDownList ID="ddlSortDirection" runat="server" AutoPostBack="True" 
            onselectedindexchanged="ddlSortDirection_SelectedIndexChanged">
</asp:DropDownList>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号