本文介绍了DropDownList SelectedIndexChanged事件在GridView HeaderTemplate中未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在工作单位网站上工作,特别是职位搜索页面。我将所发现的工作返回到 DataBound GridView (即 gvwJobs ),并且在 HeaderTemplate 中,我有一个 DropDownList 命名为 ddlSortDirection 它指定执行排序的方向:

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>

如您所见,我确保 AutoPostBack 开了。我还在 GridView DataBound 事件中创建了一个自定义事件处理程序:

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

我发现 ddlSortDirection_SelectedIndexChanged 当在 ddlSortDirection 中更改选择时,不会调用SubProcedure。我可以看到发生了一个 PostBack ,但该方法绝对不被调用。我尝试的是在 GridView 之外创建一个类似的 DropDownList ,并成功触发了 SelectedIndexChanged 事件,甚至没有一个自定义的事件处理程序!

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!

请帮助我实现我的目标,一个 DropDownList 在$ code的 HeaderTemplate 内触发 SelectedIndexChanged 事件> GridView ?

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

推荐答案

设置 EnableViewState 该GridView为false

set the EnableViewState of that GridView to false

这篇关于DropDownList SelectedIndexChanged事件在GridView HeaderTemplate中未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 16:33
查看更多