ASP.Net : Gridview Columns Edit

Introduction Grid View Column in ASP .Net

 The need for this article is always in developers mind, the concept to do each and everything dynamically is the better way in the development because it decreases the code quantity to write. Good developers always want to write short and less code for any task.

Creating gridview, binding gridview is all old concepts for now, here this article shows or describe to beautification of a gridview according to a developer’s choice.

To start work on the beautification of Gridview, first learn Gridview in ASP.net is and how to Bind Gridview in ASP.net

Source Code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %>

DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
   <title>title>
   <style type="text/css">
body
{
font-family:Verdana;
}
.mycss
{
background:Red;
font-weight:bold;
color:Blue;
}
style>
head>
<body>
   <form id="form1" runat="server">
   <div>
       <br />
       <asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound">
asp:GridView>
   div>
   form>
   <p style="text-align: center">
        p>
body>
html>

Design:

Design ll look like the below image :

 

Code Behind :

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

using System.Data.SqlClient;

 

public partial class Default4 : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        if (!IsPostBack)

        {

            BindGridviewData();

        }

 

    }

    // This method is used to bind gridview from database

    protected void BindGridviewData()

    {

        DataTable dt = new DataTable();

        dt.Columns.Add("S.No.", typeof(Int32));

        dt.Columns.Add("Name", typeof(string));

        dt.Columns.Add("Qualification", typeof(string));

        dt.Columns.Add("Country", typeof(string));

        DataRow dtrow = dt.NewRow();    // Create New Row

        dtrow["S.No."] = 1;            //Bind Data to Columns

        dtrow["Name"] = "Rapid programming";

        dtrow["Qualification"] = "Technical";

        dtrow["Country"] = "India";

        dt.Rows.Add(dtrow);

        dtrow = dt.NewRow();               // Create New Row

        dtrow["S.No."] = 2;               //Bind Data to Columns

        dtrow["Name"] = "ASP.Net";

        dtrow["Qualification"] = "Microsoft";

        dtrow["Country"] = "International";

        dt.Rows.Add(dtrow);

        GridView1.DataSource = dt;

        GridView1.DataBind();

    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

    {

        if (e.Row.RowType == DataControlRowType.DataRow)

        {

            e.Row.Cells[0].CssClass = "mycss";

            e.Row.Cells[2].CssClass = "mycss";

        }

    }

 

}

Now save whole work press ctrl+S and run the page or hit F5 Gridview ll display having data like below :

 

This is the way to modify a Gridview according to desire font color, Font type etc.