0
我讀過幾個關於如何在使用objectdatasource時執行排序和分頁的教程。我創建了一個動態的SQL存儲過程來處理分頁和排序,並且在數據庫端一切正常。當我點擊GridView標題來執行排序時,我遇到了問題。我收到以下錯誤消息:GridView'EmployeeGrid'觸發事件排序哪些未處理。我沒有在後面的代碼中編碼的排序事件,我的感覺是排序可以通過將對象數據源中的排序表達式傳遞給我的存儲過程來自動處理。如果我錯了,請糾正我。有人可以提供有關如何使用objectdatasource執行排序的任何建議嗎?如果我的東西配置不正確,請告訴我。此外,分頁工作正常。使用objectdatasource排序gridview的問題
<asp:GridView ID="EmployeeGrid" runat="server" Width="100%" AutoGenerateColumns="False"
ClientIDMode="Static" EmptyDataText="" AllowSorting="True" AllowPaging="true"
>
<Columns>
<asp:BoundField DataField="Employee_ID" HeaderText="Employee ID" SortExpression="Employee_ID" />
<asp:BoundField DataField="First_Name" HeaderText="First Name" SortExpression="First_Name" />
<asp:BoundField DataField="Last_Name" HeaderText="Last Name" SortExpression="Last_Name" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="GridDataSource" runat="server" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetDataByValue" TypeName="PO.BLL.Employee"
EnablePaging="True" SelectCountMethod="GetDataByValueCount" MaximumRowsParameterName="MaximumRows"
StartRowIndexParameterName="StartIndex" SortParameterName="sortExpression">
<SelectParameters>
<asp:ControlParameter ControlID="txtEmployeeID" Name="Employee_ID" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="txtFirstName" Name="First_Name" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="txtLastName" Name="Last_Name" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<DataObjectMethod(DataObjectMethodType.[Select])> _
Public Function GetDataByValue(ByVal Employee_ID As String,
ByVal First_Name As String, _
ByVal Last_Name As String, _
ByVal StartIndex As Integer, _
ByVal MaximumRows As Integer, _
ByVal SortExpression As String
) As EmployeeDS.EmployeeDataTable
If String.IsNullOrEmpty(SortExpression) Then
SortExpression = "Contract_ID"
End If
Return Me.Adapter.GetDataByValue(Employee_ID, _
First_Name, _
Last_Name, _
StartIndex, _
MaximumRows, _
SortExpression
)
End Function
'on search button click
Private Sub BindData()
Me.EmployeeGrid.DataSource = GridDataSource
Me.EmployeeGrid.DataBind()
End Sub
我是否必須編寫代碼來處理排序事件的排序?在我讀過的大多數教程中,當從Objectdatasource傳遞sort參數時,它會自動排序。這是不正確的? – user3397437