0

I want to make a custom paging for my gridview in asp.net 'cause i have a lot of information in my database. My problem is when i generate linkbuttons. I put them in a panel, but i have more than 7000 buttons for my pages. When i add them into my panel, it displays me all of them on 10 lines in my page. I need to display only 10 and when i press the last of them to display other 10 buttons. My code:

for (int index = 0; index < nrPages; index++)
                {
                    int pageNo = index + 1;
                    LinkButton lnk = new LinkButton();
                    lnk.Click += new EventHandler(PageChange);

                    lnk.ID = "PageLink" + pageNo.ToString();
                    lnk.CommandName = "Page";
                    lnk.Text = " " + pageNo.ToString() + " ";
                    lnk.CommandArgument = index.ToString();

                    PanelPager.Controls.Add(lnk);
                }

public void PageChange(object sender, EventArgs e)
        {
            int pageIndex = int.Parse((sender as LinkButton).CommandArgument);
            object dataSource = GetDataSource(OwnerId, null, pageIndex);
            PushData(dataSource);

        }

Here i use my linkButton

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Simply you are doing pagination of page numbers so the logic would be the same pagination as you are doing pagination of your actual data. – Chetan Jan 19 '17 at 10:33
  • Keep in mind that all 70.000+ rows are still retrieved from database/viewstate every time the GridView is loaded. That means A LOT of extra traffic for displaying just 10 rows. Start using Ajax to retrieve the page datasets. – VDWWD Jan 19 '17 at 11:08
  • @VDWWD. no there are not retrived every time.I use ROW_NUM() in my Sql server, and i load only between page index and page size – user7383186 Jan 19 '17 at 11:10

1 Answers1

0
int nrPages = 7000;

public void RenderPageNumbers(int nextPageNo)
{
    int pageSize = 10;
    int totalPages = nrPages / pageSize;
    var startIndex = ((nextPageNo -1) * pageSize ) + 1
    for (int index = startIndex; index < startIndex + pageSize; index++)
    {
        int pageNo = index;
        LinkButton lnk = new LinkButton();
        lnk.Click += new EventHandler(PageChange);

        lnk.ID = "PageLink" + pageNo.ToString();
        lnk.CommandName = "Page";
        lnk.Text = " " + pageNo.ToString() + " ";
        lnk.CommandArgument = index.ToString();

        PanelPager.Controls.Add(lnk);
    }
}
Chetan
  • 6,711
  • 3
  • 22
  • 32