Posted by : Anwar Hossain
Category : How to use grid view in asp.net c#

How to create grid view paging in asp.net using c#

Dear Viewers I will show how to paging grid view data in asp.net c#. Sometimes a big amount of data is required to load from database for displaying data using asp.net grid view control .In this case we can use grid view PageIndexChanging event . At first we need to double click on PageIndexChanging event and need to true allowpaing properties and define the PageSize properties to display what amount of data to be displayed at a time during pagechanging .

Grid view paging Example in c #.

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();
  }
}

Out Put

grid-view-paging-asp.net



Realted Article Headline

Gridview datetime format example in ASP.Net c#
Displaying total column value in the Gridview Footer using asp.net c#.
How to create grid view paging in asp.net using c#
How to bind Multi-Dimensional Arrays Data to gird view in asp.net using C#
How to bind Two-Dimensional Arrays Data to gird view in asp.net using C#
How to bind Single-Dimensional Arrays Data to gird view in asp.net using C#
how to export gridview data to pdf in asp.net c#
how to export gridview data to word in asp.net using c#
how to export gridview data to excel in c#
How to delete row from grid view showing confirmation JavaScript using asp.net c#
How to delete data from grid view using row deleting event in asp.net c#
How to bind data into gridview using code behind in asp.net c#
How to scroll gird view overflow data in asp.net c#
How to Bind data into grid view control using asp.net c#

Article Category

How to create asp.net control dynamically
Learn HTML for beginner
DataList example in C Sharp
Mail sending in asp.net c#
State Management in ASP C #
Basic sql tutorial for Beginner
DataTable example in ASP.Net C#
How to use LINQ in ASP.NET C#
asp.net c # basic tutorial
How to use ajax toolkit in asp.net C#
How to use different types of validation control using asp.net c#
How to use grid view in asp.net c#
Protected by Copyscape Online Plagiarism Detection