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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:58:03+00:00 2026-05-27T03:58:03+00:00

I want to make custom paging in GridView in ASP.Net, my data source is

  • 0

I want to make custom paging in GridView in ASP.Net, my data source is a object data.
I checked the web to find any code for this and found one which is not working for me.

  protected void invoiceReportsgridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        if (sender != null)
        {
            displayInvListgridView.PageIndex = e.NewPageIndex;
            displayInvListgridView.EditIndex = -1;
            displayInvListgridView.SelectedIndex = -1;
        }
    }

    protected void GridView_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Pager)
        {
            CustomizePageBar(e);
        }
    }

    void ProductsGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
    {
        // If multiple buttons are used in a GridView control, use the
        // CommandName property to determine which button was clicked.
        if (e.CommandName == "Add")
        {
            // Convert the row index stored in the CommandArgument
            // property to an Integer.
            int index = Convert.ToInt32(e.CommandArgument);

            // Retrieve the row that contains the button clicked 
            // by the user from the Rows collection.
            GridViewRow row = displayInvListgridView.Rows[index];

            // Create a new ListItem object for the product in the row.     
            ListItem item = new ListItem();
            item.Text = Server.HtmlDecode(row.Cells[1].Text);

            // If the product is not already in the ListBox, add the ListItem 
            // object to the Items collection of the ListBox control. 
            //if (!displayInvListgridView.Items.Contains(item))
            //{
            //    displayInvListgridView.Items.Add(item);
            //}
        }
    }

    private void CustomizePageBar(GridViewRowEventArgs e)
    {

        //Table tblPager = new Table();
        tblPager.BorderWidth = 0;
        tblPager.CellPadding = 0;
        tblPager.CellSpacing = 0;
        tblPager.Width = Unit.Percentage(100);
        tblPager.Height = Unit.Pixel(20);

        //add a row for our pager contents
        tblPager.Rows.Add(new TableRow());

        //Spacer Cell
        TableCell tcelSpace = new TableCell();
        tcelSpace.Width = Unit.Pixel(360);


        //Page x of y Cell
        TableCell tcelXofY = new TableCell();
        tcelXofY.Width = Unit.Pixel(100);

        Label litXofY = new Label();
        litXofY.Text = "Page " + (displayInvListgridView.PageIndex + 1) + " of " + displayInvListgridView.PageCount;
        litXofY.Font.Bold = true;
        tcelXofY.Controls.Add(litXofY);


        //lable GoTo
        Label lblGoto = new Label();
        lblGoto.Text = "GoTo: ";
        lblGoto.ID = "lblGoTo";
        lblGoto.Font.Bold = true;
        lblGoto.Font.Size = displayInvListgridView.PagerStyle.Font.Size;

        TableCell tcelGoto = new TableCell();
        tcelGoto.Width = Unit.Pixel(25);
        tcelGoto.Controls.Add(lblGoto);


        //Pick drop downlist
        TableCell tcelPickPage = new TableCell();
        tcelPickPage.Width = Unit.Pixel(25);
        //The dropdown list box
        DropDownList ddlPickPage = new DropDownList();
        ddlPickPage.ID = "ddlPick";
        ddlPickPage.AutoPostBack = true;
        ddlPickPage.EnableViewState = true;
        ddlPickPage.Font.Size = displayInvListgridView.PagerStyle.Font.Size;

        for (int index = 1; index <= displayInvListgridView.PageCount; index++)
        {
            ddlPickPage.Items.Add(index.ToString());
        }
        ddlPickPage.SelectedIndex = displayInvListgridView.PageIndex;

        //handle event for picklist
        ddlPickPage.SelectedIndexChanged += new EventHandler(OnPagePicked);
        tcelPickPage.Controls.Add(ddlPickPage);

        //The existing Nav controls
        TableCell tcelNav = new TableCell();
        tcelNav.Width = Unit.Pixel(150);

        //for move all existing controls
        foreach (Control ctrl in e.Row.Cells[0].Controls)
        {
            tcelNav.Controls.Add(ctrl);
        }

        // add all cells to new pager

        tblPager.Rows[0].Cells.Add(tcelSpace);
        tblPager.Rows[0].Cells.Add(tcelXofY);
        tblPager.Rows[0].Cells.Add(tcelGoto);
        tblPager.Rows[0].Cells.Add(tcelPickPage);
        tblPager.Rows[0].Cells.Add(tcelNav);


        //replace grids pager with new
        e.Row.Cells[0].Controls.Add(tblPager);

    }


    protected void OnPagePicked(object sender, EventArgs e)
    {
        DropDownList ddlPick = (DropDownList)sender;
        displayInvListgridView.PageIndex = Convert.ToInt32(ddlPick.SelectedItem.Value) - 1;
        //Raise page index changed so user can rebind data

        GridViewPageEventArgs gvArgs = new GridViewPageEventArgs(Convert.ToInt32(ddlPick.SelectedItem.Value) - 1);
        //OnPageIndexChanging(gvArgs);
        GridViewPageEventArgs ex = new GridViewPageEventArgs(Convert.ToInt32(ddlPick.SelectedItem.Value) - 1);
        invoiceReportsgridView_PageIndexChanging(sender, gvArgs);
    }
  • 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-27T03:58:03+00:00Added an answer on May 27, 2026 at 3:58 am

    The idea behind the manual Gridview paging is that you need to rebind the gridview on each page change, and also you need to change the page index. Here is a simple example:

    //This is the method to bind the gridview to the data.
    private void LoadGridview()
    {
        List<MyObject> MyObjectList = MyObject.FillMyList();
        if (MyObjectList != null && MyObjectList.Count > 0)
        {
            this.GridView1.DataSource = MyObjectList;
            this.GridView1.DataBind();
        }
    }
    
    //When the index changes
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        //Changes the page
        this.GridView1.PageIndex = e.NewPageIndex;
        LoadGridview();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        //When the page loads
        LoadGridview();
    }
    

    Good luck!

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

Sidebar

Related Questions

I want to make a custom ASP.NET control that is a subclasse of System.Web.UI.WebControls.Calendar
I have asp.net page where I am using a gridView with custom paging and
I am trying to make custom button below is the code. I want to
I want to make a custom Array object that recieves a number as index,
I want to make a custom control in my website. Following is the Code:
I want to make some custom hot keys where in any program I can
I want to make a custom print function that takes any amount of arguments
I want to make custom select from the database table using Linq. We use
I want to make a simple app, where a UIWebView with custom content will
I want to make a copy of an ActiveRecord object, changing a single field

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.