Feb 26, 2010

Changing color of a cell in datagrid and gridview contros in asp.net

In RowDataBound event of GridView

protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].BackColor = System.Drawing.Color.Gray;
}
}

In OnItemDataBound event of DataGrid

protected void ItemDB(object sender, DataGridItemEventArgs e)
{

if (Convert.ToInt16 (e.Item.Cells[6].Text) >15 )
{
e.Item.Cells[6].ForeColor = System.Drawing.Color.Green;
}
else
{
e.Item.Cells[6].ForeColor = System.Drawing.Color.Red;
}
}
}

No comments:

Post a Comment