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 8575119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:37:25+00:00 2026-06-11T19:37:25+00:00

I have set my Gridview to allow paging. try { SqlConnection sqlConnection = new

  • 0

I have set my Gridview to allow paging.

        try
        {

            SqlConnection sqlConnection = new SqlConnection("Data Source=JACKCONNECTION\\SQLEXPRESS;Initial Catalog=testbase;Integrated Security=True");
            SqlCommand sqlCommand = new SqlCommand(allitemsselectedsqlsrc, sqlConnection);
            sqlCommand.CommandType = System.Data.CommandType.Text;
            sqlConnection.Open();

            SqlDataAdapter da = new SqlDataAdapter(sqlCommand);
            DataSet ds = new DataSet();
            da.Fill(ds);

            ArrayList ArrList = new ArrayList();

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                ArrList.Add(dr);
            }
            GridViewMass.DataSource = ds;
            GridViewMass.DataBind();


        }
        catch (Exception err)
        {
            LabelSelErr.Text = err.Message;
        }

Also, I have a action PageIndexChanging for GridView as follows:

    protected void gvm_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridViewMass.PageIndex = e.NewPageIndex;
        GridViewMass.DataBind();

    }

Lastly, the aspx file contain the Gridview is as follows:

<asp:GridView ID="GridViewMass" runat="server" AllowPaging="True" 
                            AllowSorting="True" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" 
                            BorderWidth="1px" CellPadding="4" EnableSortingAndPagingCallbacks="True" 
                            ForeColor="Black" GridLines="Horizontal" 
                            onpageindexchanging="gvm_PageIndexChanging">
                            <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
                            <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
                            <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
                            <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
                            <SortedAscendingCellStyle BackColor="#F7F7F7" />
                            <SortedAscendingHeaderStyle BackColor="#4B4B4B" />
                            <SortedDescendingCellStyle BackColor="#E5E5E5" />
                            <SortedDescendingHeaderStyle BackColor="#242121" />
                        </asp:GridView>

The strange thing happen is when I click on the page (be it the 2nd page, 3rd page or whatever page that I could click), the Gridview GridViewMass will just disappear.

Did I code wrongly? Previously, I encountered the following error messages and have solved them but right now, I end up with something that I could not continue anymore.

  1. A first chance exception of type ‘System.InvalidOperationException’ occurred in System.dll
  2. there is already an open datareader associated with this command which must be closed first.
  3. The data source does not support server-side data paging.
  4. The GridView ‘GridView’ fired event PageIndexChanging which wasn’t handled.

Appreciate any help that can help me get my GridView back.

  • 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-06-11T19:37:26+00:00Added an answer on June 11, 2026 at 7:37 pm

    You are missing just one thing in your PageIndexChanging event

    protected void gvm_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        // Here you missing to give datasource to your Grid...
        GridViewMass.PageIndex = e.NewPageIndex;
        GridViewMass.DataBind();
    
    }
    

    In your Try/catch block you have to store that dataset in ViewState

        try
        {
    
            SqlConnection sqlConnection = new SqlConnection("Data Source=JACKCONNECTION\\SQLEXPRESS;Initial Catalog=testbase;Integrated Security=True");
            SqlCommand sqlCommand = new SqlCommand(allitemsselectedsqlsrc, sqlConnection);
            sqlCommand.CommandType = System.Data.CommandType.Text;
            sqlConnection.Open();
    
            SqlDataAdapter da = new SqlDataAdapter(sqlCommand);
            DataSet ds = new DataSet();
            da.Fill(ds);
    
            ArrayList ArrList = new ArrayList();
    
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                ArrList.Add(dr);
            }
            ViewState["DataSource"] = ds;
            GridViewMass.DataSource = ds;
            GridViewMass.DataBind();
    
    
        }
        catch (Exception err)
        {
            LabelSelErr.Text = err.Message;
        }
    

    Now in your pageIndexChangeing change like this

    protected void gvm_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        // Here you missing to give datasource to your Grid...
        GridViewMass.DataSource = (DataSet)(ViewState["DataSource"]);
        GridViewMass.PageIndex = e.NewPageIndex;
        GridViewMass.DataBind();
    
    }
    

    Also remember to set your EnableSortingAndPagingCallbacks to False!

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

Sidebar

Related Questions

I have a gridview that receives a data source with 8621 entries with the
I have a gridview that is set up to do paging but it is
I have to set GridView.DataKeyNames (This is really a question about the syntax for
I have a asp:GridView with a HyperLinkField . It's DataNavigateUrlFormatString property is set to
i need to set image as background in android gridview. I have code which
So, I have a GridView with an ObjectDataSource, and I want to programmatically set
I have a gridivew with auto-generated fields, whenever there is a new set of
I have set a background on the data-role=page element like so <div data-role=page style=background:
I have a GridView which retrieves data from a database. Users have roles, some
I Have a and ASP.NET GridView which is set so <asp:GridView ID=GridView1 runat=server AutoGenerateColumns=False

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.