Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6072033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:06:55+00:00 2026-05-23T10:06:55+00:00

So I’ve created a gridview, and paging/sorting handlers which I learned from guides and

  • 0

So I’ve created a gridview, and paging/sorting handlers which I learned from guides and adapted to accomodate my two gridviews :

paging

    protected void GridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        ((GridView)sender).PageIndex = e.NewPageIndex; // updatepanel allows this to happen without refreshing

    }

sorting

protected void GridView_Sort(object sender, GridViewSortEventArgs e)
        {
            string sortdir;

            ViewState["SortExpression"] = e.SortExpression;

            if (GridViewSortDirection.ToString() == "Ascending")
            {
                sortdir = "ASC";
                GridViewSortDirection = SortDirection.Descending;
            }
            else
            {
                sortdir = "DESC";
                GridViewSortDirection = SortDirection.Ascending;
            }

            var expression = e.SortExpression;

            var gv = sender as GridView;

            DataView gridv = ((DataSet)gv.DataSource).Tables[0].DefaultView; // get GridView datasource as a DataView as it is easier to sort

            gridv.Sort = expression + " " + sortdir; // strict formatted string here; e.g: Subject ASC

            gv.DataSource = gridv;

            gv.DataBind();
        }

    }

I got this all working fine a while ago, but revisiting the project now, I’m finding that changing pages requires two clicks on the page number link rather than one, and after one page change it would stop responding to clicks.

The gridviews themselves are populating with the right data and displaying. Any suggestions on where to look if you can’t quite tell what is wrong would be great.

Also I got breakpoints setup to watch if the eventhandlers are being called, and they do.

EDIT :

<asp:GridView ID="CurrentGridView" runat="server" CssClass="CurrentGridView" 
                                AllowPaging="True" AllowSorting="True"
                                AutoGenerateColumns="False" CellPadding="4" EnableModelValidation="True" ForeColor="#333333"
                                 OnSorting="GridView_Sort"
                                GridLines="None" Width="600px" EnableSortingAndPagingCallbacks="True" 
                                 OnPageIndexChanging="GridView_PageIndexChanging" >
                                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                                <Columns>
                                    <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" >
                                    <ItemStyle Width="30px" />
                                    </asp:BoundField>
                                    <asp:HyperLinkField DataNavigateUrlFields="Url" DataTextField="Subject" 
                                        HeaderText="Subject" SortExpression="Subject" >
                                    <ControlStyle CssClass="SubjectColumn" />
                                    <ItemStyle Width="200px" />
                                    </asp:HyperLinkField>
                                    <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status">
                                        <ItemStyle HorizontalAlign="Center" />
                                    </asp:BoundField>
                                    <asp:BoundField DataField="Created" HeaderText="Logged Date" 
                                        SortExpression="Created" HtmlEncodeFormatString="False">
                                        <ControlStyle CssClass="LoggedDate" />
                                        <ItemStyle HorizontalAlign="Right" Width="80px" />
                                    </asp:BoundField>
                                </Columns>
                                <EditRowStyle BackColor="#999999" />
                                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                <PagerStyle CssClass="PagerStyle"  ForeColor="White" HorizontalAlign="Center" />
                                <RowStyle BackColor="#F7F6F3" VerticalAlign="Top" ForeColor="#333333" />
                                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                            </asp:GridView>

and

<asp:GridView ID="HistoricalGridView" runat="server" 
                                AutoGenerateColumns="False" CellPadding="4" EnableSortingAndPagingCallbacks="True" EnableModelValidation="True" ForeColor="#333333"

                                GridLines="None" Width="600px">
                                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                                <Columns>
                                    <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
                                    <asp:HyperLinkField DataNavigateUrlFields="Url" DataTextField="Subject" 
                                        HeaderText="Subject" SortExpression="Subject">
                                    <ControlStyle ForeColor="#5D7B9D" />
                                    </asp:HyperLinkField>
                                    <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" >
                                        <ItemStyle HorizontalAlign="Center" />
                                    </asp:BoundField>
                                    <asp:BoundField DataField="Created" HeaderText="Logged Date" SortExpression="Created">
                                        <ItemStyle HorizontalAlign="Right" Width="80px" />
                                    </asp:BoundField>
                                </Columns>
                                <EditRowStyle BackColor="#999999" />
                                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                <PagerStyle CssClass="PagerStyle" ForeColor="White" HorizontalAlign="Center" />
                                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                            </asp:GridView>

EDIT : I can see that the DataSets are nulled by the time they get to the sort/paging handlers, but I don’t have anything explicitly reinitializing them or nulling them.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:06:55+00:00Added an answer on May 23, 2026 at 10:06 am

    You wrote:
    “EDIT : I can see that the DataSets are nulled by the time they get to the sort/paging handlers, but I don’t have anything explicitly reinitializing them or nulling them.”

    The dataset is not persisted by the grid in viewstate or anything, you need to rebind everytime you call sort or page. Give that a try and see if it fixes the issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.