DropDownList SelectedIndexChanged 事件未在 GridView HeaderTemplate 内触发

发布于 2024-08-18 11:13:45 字数 1429 浏览 6 评论 0原文

我目前正在工作委员会网站上工作,特别是工作搜索页面。我将找到的作业返回到 DataBound GridView (即 gvwJobs),并且在 HeaderTemplate 中我有一个DropDownList 名为 ddlSortDirection,指定执行排序的方向:

<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 事件上创建了一个自定义事件处理程序,如下所示:

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 中更改。我可以看到发生了 PostBack,但该方法肯定没有被调用。我尝试做的是在 GridView 之外创建一个类似的 DropDownList ,并且成功触发了 SelectedIndexChanged 事件,甚至没有自定义事件处理程序!

请您帮助我实现让 DropDownListGridViewHeaderTemplate 内触发 SelectedIndexChanged 事件的目标代码>?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光暖心i 2024-08-25 11:13:45

将该 GridView 的 EnableViewState 设置为 false

set the EnableViewState of that GridView to false

陌伤浅笑 2024-08-25 11:13:45

DropDownList 上设置 runat="server"

例如:

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

set runat="server" on DropDownList

Eg:

<asp:DropDownList ID="ddlSortDirection" runat="server" AutoPostBack="True" 
            onselectedindexchanged="ddlSortDirection_SelectedIndexChanged">
</asp:DropDownList>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文