2

We set up an ASP.Net GridView and included sorting and paging. When the user clicks on the GridView column header links for sorting the data or if the user clicks on the numbers links at the bottom of the GridView for paging the data, nothing happens.

Here is a cut down version of the markup for the GridView:

<asp:UpdatePanel 
    ID="UpdatePanelSummary" 
    runat="server" 
    UpdateMode="Always">

    <ContentTemplate> 

        <h1>Maintenance</h1>

        <% '-- GridView (Grid) for summary.                                                      -- %>
        <% '-- The user chooses a summary row from here and details are shown in a DetailsView.  -- %>
        <% '--------------------------------------------------------------------------------------- %>

        <asp:GridView
            ID="GridViewSummary" 
            runat="server" 
            AllowSorting="True" 
            AutoGenerateColumns="False" 
            DataKeyNames="ID" 
            Width="224px" 
            AllowPaging="True" 
            PageSize="7">

            <Columns>
                <asp:BoundField DataField="Unit" HeaderText="Unit" 
                    SortExpression="Unit" />

                <asp:BoundField DataField="TheName" HeaderText="Name" 
                    SortExpression="TheName" />

                <asp:BoundField DataField="ID" 
                    HeaderText="ID" SortExpression="ID" InsertVisible="False" ReadOnly="True" 
                    Visible="False" />

                <asp:CommandField ButtonType="Button" SelectText="Select Unit Details" 
                    ShowSelectButton="True" />
            </Columns>
        </asp:GridView>
    </ContentTemplate>
</asp:UpdatePanel>

Since nothing is happening, we are assuming we need to write some coding in the code-behind file. Can you show us what coding is needed to wake up the sorting and paging?

3
  • What is your DataSource? Also you are inside an UpdatePanel. UpdatePanel's behave strange when exceptions get thrown from within the partial page render request. Can you remove the UpdatePanel for debugging and see if your code-behind maybe throws an exception? Commented Dec 11, 2012 at 14:47
  • The DataSource is set from inside a VB.Net code-behind file using: Dim theTableAdapter As New DataSetClassesTableAdapters.ClassesTableAdapter Private Sub Teachers_Init(sender As Object, e As EventArgs) Handles Me.Init ' Load the data from the database into the GridView. '--------------------------------------------------- GridViewSummary.DataSource = theTableAdapter.GetDataByAllClasses GridViewSummary.DataBind() End Sub Commented Dec 11, 2012 at 14:57
  • I removed the UpdatePanel and this error was shown: The GridView 'GridViewSummary' fired event PageIndexChanging which wasn't handled. I will add the coding that Bonny Bonev suggested since it uses that event handler. Commented Dec 11, 2012 at 15:05

1 Answer 1

2

Check out this post sorting and paging with gridview asp.net

Basically you need to add server side event handlers for sorting and paging.

Here is an example - you can copy/paste most of it.

http://www.dotnetspider.com/resources/1249-Grid-View-Paging-Sorting.aspx

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the addition. I will try to convert it to VB.Net and let you know if we can get it working.
Got the paging working. Now I will work on the sorting. Thanks again. :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.