Resources » Code Snippets » ASP.NET GridView

Change GridView BackColor


Posted Date: 25-Jul-2008  Last Updated:   Category: ASP.NET GridView    
Author: Member Level: Silver    Points: 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;
break;

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

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

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

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

}


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...

Feedbacks      

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

    More...
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India