Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top