how to use pagination in gridview in

Total Post:341

C#  ASP.Net 
 870  View(s)
Rate this:
I want to use pagination in gridview  how will do please help me.
  1. Post:281

    Re: how to use pagination in gridview in

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#CC9966" BorderStyle="Solid" BorderWidth="1px" CellPadding="4" AllowPaging="True"

    OnPageIndexChanging="GridView1_PageIndexChanging" PageSize="8">


    <asp:TemplateField HeaderText="Emp_ID">


    <%#Eval("Emp_ID") %>


    <ControlStyle Width="100px"></ControlStyle>

    <HeaderStyle Width="100px" />

    <ItemStyle HorizontalAlign="Center" />


    <asp:TemplateField HeaderText="Emp_Name" >


    <%#Eval("Emp_Name") %>


    <ControlStyle Width="300px"></ControlStyle>

    <HeaderStyle Width="200px" />


    <asp:TemplateField HeaderText="Emp_Sal">


    <%#Eval("Emp_Sal") %>


    <ControlStyle Width="200px"></ControlStyle>

    <HeaderStyle Width="200px" />



    <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />

    <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />

    <PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />

    <RowStyle BackColor="White" ForeColor="#330099" />

    <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />

    <SortedAscendingCellStyle BackColor="#FEFCEB" />

    <SortedAscendingHeaderStyle BackColor="#AF0101" />

    <SortedDescendingCellStyle BackColor="#F6F0C0" />

    <SortedDescendingHeaderStyle BackColor="#7E0000" />


    using System;

    using System.Collections.Generic;

    using System.Configuration;

    using System.Data;

    using System.Data.SqlClient;

    using System.Linq;

    using System.Web;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    namespace Forumasp


    public partial class GridviewSorting : System.Web.UI.Page


    protected void Page_Load(object sender, EventArgs e)


    GridView1.DataSource = GetRecord(); //set DataSource GridView

    GridView1.DataBind(); //binding GridView


    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)


    GridView1.PageIndex = e.NewPageIndex;

    GridView1.DataSource = GetRecord();





    public DataTable GetRecord()



    DataTable dt = new DataTable();

    string constr =

    ConfigurationManager.ConnectionStrings["forumConnectionString"].ToString(); // connection string

    SqlConnection con = new SqlConnection(constr);


    SqlCommand com = new SqlCommand("select *from Employee", con); // table name

    SqlDataAdapter da = new SqlDataAdapter(com);

    DataSet ds = new DataSet();


    dt = ds.Tables[0];

    return dt;






Enter your email address here always to be updated. We promise not to spam!