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

  • Home
  • SEARCH
  • 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 6599603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:30:46+00:00 2026-05-25T18:30:46+00:00

I want to provide custom paging in grid view. <asp:GridView ID=gvFirst runat=server AutoGenerateColumns=false AllowPaging=true

  • 0

I want to provide custom paging in grid view.

 <asp:GridView ID="gvFirst" runat="server" AutoGenerateColumns="false" 
        AllowPaging="true" 
        ondatabound="gvFirst_DataBound" >
        <Columns>
            <asp:BoundField DataField="ID" HeaderText="ProductID"/>
            <asp:BoundField DataField="Name" HeaderText="ProductName" />
        </Columns>
        <PagerTemplate>
            <asp:Panel ID="pnlPager" runat="server">
            </asp:Panel>
        </PagerTemplate>
    </asp:GridView>

If I create button here and bind click event then it is fire, but problem is this event occur for each row bind with grid

protected void gvFirst_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Pager)
        {
            Panel pnPager = e.Row.FindControl("pnlPager") as Panel;
            if (pnPager != null)
            {
                Button btnFirst = new Button();
                btnFirst.Text = "1";
                btnFirst.Click += new EventHandler(btnFirst_Click);
                pnPager.Controls.Add(btnFirst);
            }
        }
    }

If I create button here and bind click event then it is not fire; this event fire after all the rows bind to grid, so it will occur only once.

protected void gvFirst_DataBound(object sender, EventArgs e)
    {
        GridViewRow gvRow = gvFirst.BottomPagerRow;
        if (gvRow != null)
        {
            Panel pnPager = gvRow.FindControl("pnlPager") as Panel;
            if (pnPager != null)
            {
                Button btnFirst = new Button();
                btnFirst.Text = "1";
                btnFirst.Click += new EventHandler(btnFirst_Click);
                pnPager.Controls.Add(btnFirst);
            }
        }
    }

    void btnFirst_Click(object sender, EventArgs e)
    {
        using (_NorthWindDataContext = new NorthWindDataContext())
        {
            var ProductInformation = from p in _NorthWindDataContext.Products
                                     select new
                                     {
                                         ID = p.ProductID,
                                         Name = p.ProductName
                                     };
            gvFirst.DataSource = ProductInformation.Skip(5).Take(5);
            gvFirst.DataBind();
        }
    }

Another problem which I am facing is I want to provide custom paging. Now I have set page size to 5 and I am fetching 5 record from query so my grid pager is not display.

public class Productinformation
{
    public int PID
    {
        get;
        set;
    }
    public string PName
    {
        get;
        set;
    }
}
 using (NorthWindDataContext _NorthWindDataContext = new NorthWindDataContext())
        {
            Proinfo = new List<Productinformation>();
            Proinfo = (from p in _NorthWindDataContext.Products
                       select new Productinformation
                       {
                           PID = p.ProductID,
                           PName = p.ProductName,
                       }).ToList();

            gvFirst.DataSource =  Proinfo.Take(PageSize) ;
            gvFirst.DataBind();
        }

Proinfo variable declare globally.

Now when I bind I run this code it will give me error the data source does not support server-side data paging. If I use var type of variable then it is worked but we can’t declare var type of variable globally, so I used it then I have to call this method every time in paging, and I don’t want to use Objectdatasource.

  • 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-25T18:30:46+00:00Added an answer on May 25, 2026 at 6:30 pm
    1. GridView’s RowCreated indeed will be called for every row in GridView, because that is the event where the GridView will (re)create the GridViewRows. But if you check for if (e.Row.RowType == DataControlRowType.Pager) there will be no overhead. This event is perfect for creating dynamic controls because it’s called even on postback(as against RowDataBound). So your first way should be the correct one.
    2. If you want to show the pager also when there are less than PageSize rows, you should force the pager to be visible e.g. in GridView’s overridden OnPreRender.

      GridViewRow pagerRow = (GridViewRow) this.BottomPagerRow;    
      if(pagerRow != null) pagerRow.Visible = true;
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement a DataGrid in ASP.NET, and want to achieve custom paging
I want to provide a custom view in the admin very similar to changelist_view()
I want to provide a custom Batcher for Hibernate to use (for this reason:
I want to host StyleCop in a Custom Environment, the sample code provided in
I want sell some .NET library and I want provide edition with full source
I want to provide silverlight app to my customer while hosting the app at
I want to provide a piece of Javascript code that will work on any
I want to provide dynamic download of files. These files can be generated on-the-fly
I want to provide my user with some meaningful error messages when network requests
I want to provide my colleagues with an interface (using Windows Forms or WPF)

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.