HTML
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Grid view Paging</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="gvStudentList" AutoGenerateColumns="false" CellPadding="5"
runat="server" AllowPaging="True"
onpageindexchanging="gvStudentList_PageIndexChanging" PageSize="6"
Width="50%">
<Columns>
<asp:BoundField HeaderText="Student Name" DataField="_StudentName" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField HeaderText="Student Phone" DataField="_StudentPhone" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField HeaderText="Adress " DataField="_StudentAddress" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField HeaderText="Due Payment" DataField="_DuePayment" ItemStyle-HorizontalAlign="Center" />
</Columns>
<HeaderStyle BackColor="#0066FF" Font-Bold="true" ForeColor="White" />
<FooterStyle BackColor="#3366CC" />
</asp:GridView>
</div>
</form>
</body>
</html>
CODE BEHIND
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class TestDesign_GridViewPagingExample : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
AllStudentList();
}
}
//Create temporarydata but real time data will be loaded form database
private void AllStudentList()
{
List<Student> StudentList = new List<Student>();
StudentList.Add(new Student("Iqbal Hossain", "01916751804", "Noakhali", 50000));
StudentList.Add(new Student("Jabed Hossain", "01916751805", "Lakmipur", 70000));
StudentList.Add(new Student("Fazlul Goni Roman", "01916751806", "Chandpur", 80000));
StudentList.Add(new Student("Prince Hossain", "01916751807", "Rangpur", 90000));
StudentList.Add(new Student("Mr Khorsed Alam", "01916751864", "Narayangonj", 50000));
StudentList.Add(new Student("Sumay Akter", "01916751804", "Sirajgonj", 50000));
StudentList.Add(new Student("Siful Islam", "01916751808", "Dhaka", 1000000));
StudentList.Add(new Student("Abul Kasem", "01916751807", "Rangpur", 90000));
StudentList.Add(new Student("Jamala Hossain", "01916751964", "Chittagong", 50000));
StudentList.Add(new Student("Helal Ahmed", "01916751806", "Jessore", 50000));
StudentList.Add(new Student("Nasim ul Goni", "01916751808", "Dinajpur", 1000000));
gvStudentList.DataSource = StudentList;
gvStudentList.DataBind();
}
//Create student class for temporarydata
public class Student
{
public Student(string StudentName, string StudentPhone, string StudentAddress, decimal DuePayment)
{
_StudentName = StudentName;
_StudentPhone = StudentPhone;
_StudentAddress = StudentAddress;
_DuePayment = DuePayment;
}
public string _StudentName { get; set; }
public string _StudentPhone { get; set; }
public string _StudentAddress { get; set; }
public decimal _DuePayment { get; set; }
}
//PageIndexChanging Event
protected void gvStudentList_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvStudentList.PageIndex = e.NewPageIndex;
AllStudentList();
}
}