Gridview row background color change while editing?

I am having problems editing the background color of a gridview row when editing it.

The fact is that I use the RowDataBound event RowDataBound to change e.Row.BackColor based on the criteria when displaying the report (3 different colors depending on the result). For rows that do not fit these criteria, when you click the Edit button, the GridView <EditRowStyle BackColor="#999999" /> property is applied.

However, I cannot find a way to change the color of those that fall under the criteria, since the RowDataBound seems to be called all the time, overriding any changes I make.

Any suggestions?

+4
source share
5 answers

write one row in the Grid RowEditing event:

 GridView1.EditRowStyle.BackColor = System.Drawing.Color.LightYellow; 
+12
source

Hope this helps. Customize GridView row editing. That should be enough. Let me know if you need some more.

 protected void uxGrid_RowEditing(object sender, GridViewEditEventArgs e) { ClearBackColor(); GridViewRow row = uxGrid.Rows[e.NewEditIndex]; row.BackColor = Color.LightYellow; } private void ClearBackColor() { foreach (GridViewRow row in uxGrid.Rows) { row.BackColor = System.Drawing.Color.Transparent; } } 
+1
source

Try:

 <asp:GridView runat="server" > <Columns> </Columns> <EditRowStyle BackColor="#999999" /> <SelectedRowStyle BackColor="#999999" /> </asp:GridView> 
+1
source

Why not write your own logical method to change the color of the lines back ?, loop through the lines, this avoids the problem of postback ... maybe!

0
source

As @Rami said, create a method that traverses the rows of the DataGrid and changes color. Call this method in the PreRender event handler. In this way, you call this method after each postback.

0
source

All Articles