»Dotnet Ads
»Message Boards
Message Boards
Dotnet Books
»Member Details
Register
Login
LogOut
Submit Code
Submit Jobs
Submit Projects
»Competition
Community
Winners
Prizes
Write For Us
Members
»Other Resources
Links
Dotnet Resources
|
change the specific Row / Column color in DataGridView // To change the specific Row / Column color in DataGridView
//Let in a DataGridView Three Columns one is customerid,customername,age
//this code will change color for thoge rows / columns that have Age > 35
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int iAge =Convert.ToInt32( DataBinder.Eval(e.Row.DataItem, "Age").ToString());
if(iAge>35)
{
e.Row.BackColor = System.Drawing.Color.FromArgb(255,234,255); // Full row color
e.Row.Cells[3].BackColor = System.Drawing.Color.Yellow; // Column color
e.Row.ForeColor = System.Drawing.Color.Red; // Change the row's Text color
e.Row.Font.Italic = true;
e.Row.Cells[0].Controls.Add(ControlObject); // to add runtime control in GridView
}
}
}
With Best Regards
Rajendra
|