Completely Free .NET word API

Resources » Code Snippets » ASP.NET GridView

Change GridView BackColor

Updated: Category: ASP.NET GridView
Author: Member Level: SilverPoints: 5

The code sample is written in C#. It handles the DataBound event for a GridView control. When the event occurs, the row color of the GridView control is changed according to a Label in the page.

protected void GridView1_DataBound(object sender, EventArgs e)
double Gridrow = GridView1.Rows.Count;
for (int i = 0; i < Gridrow; i++)
GridViewRow row;
row = GridView1.Rows[i];

string Cplace;
Cplace = ((Label)row.Cells[2].FindControl("Label3")).Text;

switch (Cplace)
case "Pali":
row.BackColor = System.Drawing.Color.Cyan;

case "Colcatta":
row.BackColor = System.Drawing.Color.SkyBlue;

case "Goa":
row.BackColor = System.Drawing.Color.Salmon;

case "Delhi":
row.BackColor = System.Drawing.Color.SeaGreen;

case "Chennai":
row.BackColor = System.Drawing.Color.Snow;


Did you like this resource? Share it with your friends and show your love!

Responses to "Change GridView BackColor"

No responses found. Be the first to respond...


Post Comment:

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)

    Type the numbers and letters shown on the left.

    Submit Article     Return to Article Index
    Subscribe to Subscribers
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John

    Online Members

    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India