Populer Topics

GridView Control

GridView control is a grid control which display data in tabular format. It means we can bind table with GridView which can be display under gridview.

Each record of table becomes row of gridview and each columns of table be comes columns of gridview control. This is most powerful rich data control widely use in Ado.Net programming.

GridView has inbuilt features edit , update, delete or insert directly into gridview.

This probably most powerful features which abstract programmer to use gridview control in Ado.Net programming.

GridView control support following property.

Property Description

Allow us to set passing if table data is to long. By default value is false we can set it true.


This property is used to set the size of the page to display a record default value of page size is 10.


Allow us to sort data in gridview.


Allow us to generate all the columns which are in bounded data table.


Display delete link button along with row of gridview to delete data of gridview.


Display edit link button along with row of gridview to edit data of gridview.


Display select link button along with row of grid view to select data of gridview.


This is runtime property which allow us to specific data source.


.Aspx File

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" 
Inherits="Codeplanex.WebForm2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <form id="form1" runat="server">
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            CellPadding="4" ForeColor="#333333" GridLines="None">
            <AlternatingRowStyle BackColor="White" />
                <asp:BoundField HeaderText="Sr. No" />
                <asp:BoundField HeaderText="Employee Name" />
                <asp:BoundField HeaderText="Mobile" />
            <EditRowStyle BackColor="#2461BF" />
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#EFF3FB" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <SortedAscendingCellStyle BackColor="#F5F7FB" />
            <SortedAscendingHeaderStyle BackColor="#6D95E1" />
            <SortedDescendingCellStyle BackColor="#E9EBEF" />
            <SortedDescendingHeaderStyle BackColor="#4870BE" />


.Cs File

using System;
using System.Data.SqlClient;

namespace Codeplanex
    public partial class WebForm2 : System.Web.UI.Page
        SqlConnection con=new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=Demo;Integrated Security=True");
        protected void Page_Load(object sender, EventArgs e)
            if (!IsPostBack)
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = con;
                cmd.CommandText = "Select * from GridViewDemo";
                GridView1.DataSource = cmd.ExecuteReader();


Method Description

Allow us to bind the data which specifies datasource. Datasource can be datasource or datatable.


Delete specified row from grid view. We need to give index integer number to delete specified row.


Update specified row from gridview. We need to give index interger number to update specified row.


Event Description

This raised when row is delete from gridview.


It Raise when row is editing from gridview.


It raise when row updating.


This event change after selected index is changed in gridview control.