0

I'm using ASP.net web application with c#. In my web application I have a webpage with a data grid view.

I'm using this method to bind data to data grid view

 public void fillGridByALLBDetails()
    {
        GVView01.DataSource = new LibraryCatalogueOP().getLibraryCatalogue();
        GVView01.DataBind();   
    }

I'm calling the data grid view bind method in the page load event like this.

  if (!IsPostBack)
            {
                fillGridByALLBDetails();
            }

This is my business layer method to get the data.

     public DataTable getLibraryCatalogue()
{
    string myQuery1 = "EXEC SelectLibraryCatalogue";
    return new DataAccessLayer().ExecuteMyTable(myQuery1);
}

Sometimes my data grid loads a lots of data at once. I want to know how to achieve PAGING with this code. Any code example would be really great.

Thanks in advance.

Sahil
  • 137
  • 1
  • 1
  • 12
  • you can use `pagesize=10` (or 20 whatever size of page you want to display )property of gridview in designer page and provide `allowpaging=true` in designer you can get both properties – Ameya Deshpande Nov 03 '14 at 05:42

3 Answers3

1

Go through this detailed example

http://www.aspsnippets.com/Articles/Paging-in-ASPNet-GridView-Example.aspx

vallabha
  • 385
  • 1
  • 12
1

You can do it by using the properties

  <asp:gridview id="GVView01" 
            allowpaging="true" 
            pagesize="15"
            runat="server">

you can use pagesize="10" (or 20 whatever size of page you want to display )property of gridview in designer page and provide allowpaging="true" , in designer you can get both properties

Ameya Deshpande
  • 3,580
  • 4
  • 30
  • 46
1
<asp:GridView ID="GridView1" runat="server"
    AutoGenerateColumns = "false" Font-Names = "Arial"
    Font-Size = "11pt" AlternatingRowStyle-BackColor = "#C2D69B" 
    HeaderStyle-BackColor = "green" AllowPaging ="true"  
    OnPageIndexChanging = "OnPaging"
    PageSize = "10" >

. . .

And now in order make the paging functionality work we will need to add the OnPageIndexChanging event of the GridView control

protected void OnPaging(object sender, GridViewPageEventArgs e)
{
    GridView1.PageIndex = e.NewPageIndex;
    GridView1.DataBind();
}
Arunprasanth K V
  • 20,733
  • 8
  • 41
  • 71