Implement default paging in an aspnet gridview without using datasource controls Part 53











>> YOUR LINK HERE: ___ http://youtube.com/watch?v=6mEZCgO-jxA

Link for csharp, asp.net, ado.net, dotnet basics and sql server video tutorial playlists •    / kudvenkat   • Link for text version of this video • http://csharp-video-tutorials.blogspo... • Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help. •    / @aarvikitchen5572   • In this video we will discuss about implementing default paging in a gridview control that does not use any data source controls. • Step 1: Add a class file with name = EmployeeDataAccessLayer.cs . • using System; • using System.Collections.Generic; • using System.Linq; • using System.Web; • using System.Data; • using System.Data.SqlClient; • using System.Configuration; • namespace Demo • { • public class Employee • { • public int EmployeeId { get; set; } • public string Name { get; set; } • public string Gender { get; set; } • public string City { get; set; } • } • • public class EmployeeDataAccessLayer • { • // Replace square brackets with angular brackets • public static List[Employee] GetAllEmployees() • { • // Replace square brackets with angular brackets • List[Employee] listEmployees = new List[Employee](); • string CS = ConfigurationManager.ConnectionStrings[ DBCS ].ConnectionString; • using (SqlConnection con = new SqlConnection(CS)) • { • SqlCommand cmd = new SqlCommand( Select * from tblEmployee , con); • con.Open(); • SqlDataReader rdr = cmd.ExecuteReader(); • while (rdr.Read()) • { • Employee employee = new Employee(); • employee.EmployeeId = Convert.ToInt32(rdr[ EmployeeId ]); • employee.Name = rdr[ Name ].ToString(); • employee.Gender = rdr[ Gender ].ToString(); • employee.City = rdr[ City ].ToString(); • listEmployees.Add(employee); • } • } • return listEmployees; • } • } • } • Step 2: Drag and drop a gridview control on webform1.aspx and set the following properties of GridView1 control • AllowPaging= true • PageSize= 3 • Step 3: Generate event handler method for PageIndexChanging event of GridView control. • Step 4: Copy and paste the following code in webform1.aspx.cs • protected void Page_Load(object sender, EventArgs e) • { • if (!IsPostBack) • { • GridView1.DataSource = EmployeeDataAccessLayer.GetAllEmployees(); • GridView1.DataBind(); • } • } • protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) • { • GridView1.PageIndex = e.NewPageIndex; • GridView1.DataSource = EmployeeDataAccessLayer.GetAllEmployees(); • GridView1.DataBind(); • }

#############################









New on site
Content Report
Youtor.org / YTube video Downloader © 2025

created by www.youtor.org