DropDownList SelectedIndexChanged事件未在GridView HeaderTemplate中触发

时间:2010-01-21 12:36:52

标签: gridview drop-down-menu selectedindexchanged

我正在创建一个招聘委员会网站,特别是职位搜索页面。我将找到的工作返回到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事件,甚至没有自定义事件处理程序!

请问我能帮助我实现SelectedIndexChangedDropDownList SelectedIndexChanged HeaderTemplateGridView触发{{1}}事件的目标吗?

2 个答案:

答案 0 :(得分:1)

将该GridView的EnableViewState设置为false

答案 1 :(得分:-1)

runat="server"

上设置DropDownList

例如:

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