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

How to bind data into gridview using code behind in c#

Dear viewers I will Show how to bind data using code behind row data bound event in c#. So wait to see the process. After taking grid view take Item-template field and double click the row data bound Event .

Data bind into Gridview using code behind


GridView ID="grdStudentList" runat="server" AutoGenerateColumns="False"
  Width="50%" onrowdatabound="grdStudentList_RowDataBound">
  <asp:TemplateField HeaderText="StudentName" ItemStyle-HorizontalAlign="Center">
  <ItemStyle HorizontalAlign="Center"></ItemStyle>
  <asp:TemplateField HeaderText=" Student Age " ItemStyle-HorizontalAlign="Center">
  <ItemStyle HorizontalAlign="Center"></ItemStyle>
  <asp:TemplateField HeaderText=" Address" ItemStyle-HorizontalAlign="Center">
  <ItemStyle HorizontalAlign="Center"></ItemStyle>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls


partial class TestDesign_Default : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
  if (!IsPostBack)
private void LoadAllStudent()
  List<Student> list = new List<Student>();
  list.Add(new Student("Samim", 39,"Dhaka"));
  list.Add(new Student("Asad", 48,"Chittagong"));
  list.Add(new Student("Nayed", 39,"Sylhet"));
  list.Add(new Student("Anwar", 48,"Dhaka"));
  grdStudentList.DataSource = list;
//I have created Student class
public class Student
  public Student(string StudentName, int StudentAge, string Address)
  _StudentName = StudentName;
  _StudentAge = StudentAge;
  _Address = Address;
  private string _Address;
  public string Address
  get { return _Address; }
  set { _Address = value; }
  private int _StudentAge;
  public int StudentAge
  get { return _StudentAge; }
  set { _StudentAge = value; }
  private string _StudentName;
  public string StudentName
  get { return _StudentName; }
  set { _StudentName = value; }
protected void grdStudentList_RowDataBound(object sender, GridViewRowEventArgs e)
  if (e.Row.RowType == DataControlRowType.DataRow)
  Student entry = e.Row.DataItem as Student;
  e.Row.Cells[0].Text = entry.StudentName;
  e.Row.Cells[1].Text = entry.StudentAge.ToString();
  e.Row.Cells[2].Text = entry.Address;

Out Put


Realted Article Headline

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

Article Category

How to create control dynamically
Learn HTML for beginner
DataList example in C Sharp
Mail sending in 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# c # basic tutorial
How to use ajax toolkit in C#
How to use different types of validation control using c#
How to use grid view in c#
Protected by Copyscape Online Plagiarism Detection