.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Change the background color of Gridview cell programmatically

Posted By: Ramesh     Posted Date: May 10, 2010    Points:2   Category :ASP.Net
Hi,

How to change the background color of the gridview cell based on some condition programmatically.

Suppose the value of the cell is less than 50 than the color of the gridview is red and so on.

I need to do programmatically using C#

Regards
Ramesh

Responses
Author: BangaruBabuPureti             
Posted Date: May 11, 2010     Points: 5   

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{

e.Row.Cells[2].BackColor = System.Drawing.Color.Red;
}
}

Check This Code Under Event Rawdatabound

BangaruBabu Pureti
http://bangarubabupureti.spaces.live.com/
Author: Lalij Mer             
Posted Date: May 11, 2010     Points: 5   

Use this code sample

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{

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

{

if (e.Row.Cells[1].Text == "ANTON")

{

e.Row.Cells[1].Style.Add("background-color","red");

}

}

}

Show here step by step info
http://fredrik.nsquared2.com/ViewPost.aspx?PostId=429


Please Check my answer if you help....
Thank You...

Lalit.


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend