Subscribe to Subscribers
Talk to Webmaster Tony John

Online Members

More...


Resources » Code Snippets » ASP.NET GridView

Change GridView BackColor


Posted Date:     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.


    Next Resource: How to retrieve column names using datareader? - Part II
    Previous Resource: To setup a hyperlink field to display images in GridView
    Return to Resources
    Post New Resource
    Category: ASP.NET GridView


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    GridView Row Color  .  GridView BackColor  .  Change GridView's BackColor in ASP.NET  .  Change GridView's BackColor  .  



    Follow us on Twitter: https://twitter.com/dotnetspider

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.