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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:00:03+00:00 2026-05-23T23:00:03+00:00

i have a asp.net webpage with a GridView <asp:GridView ID=grid_view runat=server AllowPaging=True AutoGenerateColumns=False BackColor=White

  • 0

i have a asp.net webpage with a GridView

<asp:GridView ID="grid_view" runat="server" AllowPaging="True" 
    AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" 
    BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" 
    GridLines="Vertical">
    <FooterStyle BackColor="#CCCCCC" />
    <Columns>
        <asp:BoundField DataField="adc" HeaderText="Posa No." />
        <asp:BoundField DataField="cde" HeaderText="Unit" />
        <asp:BoundField DataField="efg" HeaderText="User" />
        <asp:BoundField DataField="hj" HeaderText="Posa Date" />
    </Columns>
    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" /> 
    <AlternatingRowStyle BackColor="#CCCCCC" />
</asp:GridView>

and my code behind is

protected void Page_Load(object sender, EventArgs e)
{
  con = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
  gridfil();
}


public void gridfil()
{
  con.Open();
  cmd = new SqlCommand("select a,b,c from xyz where approved='sss'", con);
  SqlDataAdapter da = new SqlDataAdapter(cmd);
  SqlCommandBuilder cb = new SqlCommandBuilder(da);
  DataSet ds = new DataSet();
  da.Fill(ds);
  grid_view.DataSource = ds;
  grid_view.DataBind();
  //rd.Close();
  da.Dispose();
  cmd.Dispose();
  con.Close();
}

protected void grid_view_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
  grid_view.PageIndex = e.NewPageIndex;
  gridfil();
}

My problem is grid view was diplayed but the page indexing not working…
Does anyone have any suggestions?

  • 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-23T23:00:09+00:00Added an answer on May 23, 2026 at 11:00 pm

    Put your page load code under !IsPostBack()

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            con = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
            gridfil();
        }
    }
    

    Reason: Whenever you click on Page Number and want to view another page, Page will be postback and your page load event fired before grid_view_PageIndexChanging and it will rebind the gridview and your event will be lost and it will not fire PageIndexChanging event.

    Secondly change this and see the comments

    protected void grid_view_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
      gridfil(); // First bind the gridview 
      grid_view.PageIndex = e.NewPageIndex; // then change the page Index
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET webpage running under IIS that uses a common assembly that
Scenario: You have an ASP.Net webpage that should display the next image in a
I have an ASP.NET 2.0 (C#) webpage with a link that pulls a blob
I have an ASP.net page. When I am closing the webpage I need to
We have an advanced webpage (ASP.NET, C#), and a application which needs to be
I have an ASP.NET 3.5 page with a gridview databound to a generic list
I have user control on a ASP.NET web page, which contains a GridView and
Here's the scenario: I have an asp.net webpage which displays dynamic data in a
The Scenario: I have an ASP.Net webpage which I intend to use for letting
I have an ASP.NET web page that displays a variety of fields that need

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.