Search code examples
c#asp.netgridviewrowdatabound

How to set the background color on a gridview row


I was trying fire a row data bind event to a grid view. When data is being bound to grid view, i would like to check a condidtion , if the condidtion is satisfied , then i need to apply some color to that entire row..Please check the below code i am using..

protected void GridView4_RowDataBound(object sender, GridViewRowEventArgs e)
{

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

    Textbox txtBox1 = (GridView)(e.Row.FindControl("Name of text box"));

      if(Condidtion)
      {
          txtBox1.enabled=false;
          txtBox1.bgcolor=somecolor;
      } 

   }

}

Please help me on this..


Solution

  • below will change the color of row

      if(Condidtion)
      {
          e.Row.BackColor =somecolor;
      }