views:

33

answers:

3

Hi all, I'm having some trouble with editing a gridview row's background color when Editing it.

The thing is, I am using the RowDataBound event method to change e.Row.BackColor based on a criteria when displaying the report( 3 different colors depending on result ). For the rows that don't fall under that criteria, a GridView's property <EditRowStyle BackColor="#999999" /> is applied upon clicking the Edit button.

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

Any suggestions?

A: 

Why not write you own logic method to change rows back color?, loop through rows, this you can avoid the postback issue...maybe!

Rami Shareef
A: 

As @Rami said create a method that loops through the DataGrid rows and change the color. Call this mehtod in PreRender event handler. This way you are calling this method once every postback.

sh_kamalh
A: 

Hope this helps. Configure gridview row editing. This should be enough information. 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 = System.Drawing.Color.LightYellow;
    }



private void ClearBackColor()
        {
            foreach (GridViewRow row in uxGrid.Rows)
            {
                row.BackColor = System.Drawing.Color.Transparent;
            }
        }
Kirit Chandran