Sunday, January 13, 2013

How to Change Cell color in GridView


We can change the cell color of a GridView by using the OnRowCreated event.

.aspx code.

<asp:GridView ID="ctlGridView" runat="server" OnRowCreated="OnRowCreated" />

.cs code

protected void OnRowCreated(object sender, GridViewRowEventArgs e)
{
  if (e.Row.RowType == DataControlRowType.DataRow)
   {
    if(e.Row.Cells[3].Text=="Error")
     {
       e.Row.Cells[3].ForeColor = Color.Red;
     }
   }
}

No comments:
Write comments
Recommended Posts × +