DropDownList SelectedIndexChanged 事件未在 GridView HeaderTemplate 内触发
我目前正在工作委员会网站上工作,特别是工作搜索页面。我将找到的作业返回到 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 事件,甚至没有自定义事件处理程序!
请您帮助我实现让 DropDownList
在 GridView
的 HeaderTemplate
内触发 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将该 GridView 的
EnableViewState
设置为 falseset the
EnableViewState
of that GridView to false在
DropDownList
上设置runat="server"
例如:
set
runat="server"
onDropDownList
Eg: