我正在创建一个招聘委员会网站,特别是职位搜索页面。我将找到的工作返回到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
的{{1}}事件上创建了一个自定义事件处理程序,如下所示:
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
SubProcedure。我可以看到ddlSortDirection
发生了,但绝对没有调用该方法。我尝试过做的是在PostBack
之外创建一个类似的DropDownList
并成功触发GridView
事件,甚至没有自定义事件处理程序!
请问我能帮助我实现SelectedIndexChanged
在DropDownList
SelectedIndexChanged
HeaderTemplate
内GridView
触发{{1}}事件的目标吗?
答案 0 :(得分:1)
将该GridView的EnableViewState
设置为false
答案 1 :(得分:-1)
在runat="server"
DropDownList
例如:
<asp:DropDownList ID="ddlSortDirection" runat="server" AutoPostBack="True"
onselectedindexchanged="ddlSortDirection_SelectedIndexChanged">
</asp:DropDownList>