0
votes

I've read a few tutorials on how to perform sorting and paging when using an objectdatasource. I've created a dynamic sql stored procedure to handle the paging and sorting and everything works fine on the database side. I'm having an issue when I click on the gridview headers to perform sorting. I receive the following error message: The GridView 'EmployeeGrid' fired event Sorting which wasn't handled. I do not have a sorting event coded in the code behind, I was under the impression that sorting could be handled automatically by passing a sort expression from the object datasource to my stored procedure. Please correct me if I'm wrong. Can someone offer any advice on how to perform sorting using an objectdatasource? If I have something configured incorrectly, please let me know. Also, paging works fine.

   <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
1

1 Answers

0
votes

The GridView has a property called "OnSorting" that is the name of the backend function that handles the event. Try adding that and see what happens.