.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 row color in GridView

Posted By: priya     Posted Date: February 17, 2009    Points:2   Category :ASP.Net
How to change the row color in GridView depending upon the value of the column one value.

ex.
if the first column cell value is less than 10 then the row color will be red.

How to do that in asp.net.I am using C# as code behind.

Responses
Author: Akhil Raj       [Moderator]      
Posted Date: February 18, 2009     Points: 5   

hi friend,
Please try rowbinding event of the gridview

Author: Athira Sreejith             
Posted Date: February 22, 2009     Points: 5   

Hi..

Refer this code:

protected void gvTourProgram_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridViewRow gvRow = e.Row;
Label mylblObjective = (Label)e.Row.FindControl("lblObjective");
ImageButton mybtnDelete = (ImageButton)e.Row.FindControl("btnDelete");
CheckBox mychkboxApproval = (CheckBox)e.Row.FindControl("chkApproval");
if (mychkboxApproval.Checked)
{
// mybtnDelete.Enabled = false;
mybtnDelete.Visible = false;
}
else
{
// mybtnDelete.Enabled = true;
mybtnDelete.Visible = true;
}

string strObjective = mylblObjective.Text;
if (strObjective.ToUpper() == "SUNDAY")
{
for (int i = 3; i < gvTourProgram.Columns.Count; i++)
{
if (i != 5)
{
gvRow.Cells[i].Text = string.Empty;
}
else
{
gvRow.Cells[i].ForeColor = System.Drawing.Color.Red;
gvRow.Cells[i].Font.Bold = true;
gvRow.Cells[i].Font.Size = 10;
gvRow.Cells[i].Text = "SUNDAY";
}
}
}

if (strObjective.ToUpper() == "HOLIDAY")
{
for (int i = 3; i < gvTourProgram.Columns.Count; i++)
{
if (i != 5)
{
gvRow.Cells[i].Text = string.Empty;
}
else
{
gvRow.Cells[i].ForeColor = System.Drawing.Color.Green;
gvRow.Cells[i].Font.Bold = true;
gvRow.Cells[i].Font.Size = 10;
gvRow.Cells[i].Text = "HOLIDAY";
}
}
}
}
}



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