C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Change GridView BackColor


Posted Date: 25 Jul 2008    Resource Type: Code Snippets    Category: ASP.NET GridView

Posted By: Roshan R Mhatre       Member Level: Gold
Rating:     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;
}
}

}





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
GridView Row Color  .  GridView BackColor  .  Change GridView's BackColor in ASP.NET  .  Change GridView's BackColor  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
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 Discussion Resource Index
Post New Resource
Category: ASP.NET GridView


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

masks masks masks

Contact Us    Privacy Policy    Terms Of Use