2010-01-21 93 views
2

我正在工作板網站上工作,特別是當前的求職頁面。我回國發現成DataBoundGridView(即gvwJobs)的工作,並HeaderTemplate內我有一個DropDownList名爲ddlSortDirection指定在其中進行排序的方向:DropDownList SelectedIndexChanged事件在GridView中沒有觸發HeaderTemplate

<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處於打開狀態。我也創建於GridViewDataBound事件自定義事件處理程序,像這樣:

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改變時ddlSortDirection_SelectedIndexChanged子過程不叫。我可以看到發生了一個PostBack,但該方法絕對不會被調用。我試過的做法是在GridView之外創建一個類似的DropDownList,併成功觸發了SelectedIndexChanged事件,甚至沒有自定義事件處理程序!

請您幫我實現一個DropDownListGridViewHeaderTemplate範圍內發起SelectedIndexChanged事件的目標嗎?

回答

1

設置的GridView的EnableViewState

-1

設置runat="server"DropDownList

如:

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