Change Gridview editing row background color

Is it possible through the Design editor to assign the backround color for a gridview row that is currently being edited? I have tried creating a Custom Attribute entry using the example of <EditRowStyle BackColor="#ffff99" /> in different name and value combinations but none work. I am looking into doing this using the _RowCommand(object sender, GridViewCommandEventArgs e) … if(e.CommandName==“Edit”) in .Net code behind.

Thanks,

James

Hi James,

I recommend you using CSS or JQuery code by including it in the Web References section.
For example, you can locate the first row that contains a column that contains an input field (textbox) and change the color of the row to the desired color. (If the row contains a textbox field, that means it is in edit mode).

Regards,
Eddy

James,

Not the neatest code but if you want to do something in code behind to set the row color, you can try to change cell backcolor instead:

 protected void Page_Load(object sender, EventArgs e)
 {
     base.Page_Load(sender, e);
     
     //--- instantiate the RowDataBound event
     REQUEST_GRIDVIEW1.RowDataBound += Gridview_RowDataBound;
     
     //--- run the event when page is first loaded to apply the formatting
     if (!IsPostBack)
     { REQUEST_GRIDVIEW1.DataBind(); }
 }



protected void Gridview_RowDataBound(object sender, GridViewRowEventArgs e)
{
    
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
       if (e.Row.RowState == DataControlRowState.Edit ||
             e.Row.RowState == (DataControlRowState.Alternate | DataControlRowState.Edit))
        {
            for (int i=0; i< e.Row.Cells.Count; i++)
            {  e.Row.Cells[i].BackColor  = System.Drawing.Color.LightPink;  }
            
  
        }
    }
}

image