Eton B.
Eton B.

Reputation: 6281

Changing Gridview row background color when editing?

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?

Upvotes: 4

Views: 16170

Answers (5)

sh_kamalh
sh_kamalh

Reputation: 3901

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

Upvotes: 0

Mian Fida
Mian Fida

Reputation: 146

write a single line in Grid RowEditing Event:

GridView1.EditRowStyle.BackColor = System.Drawing.Color.LightYellow; 

Upvotes: 13

abatishchev
abatishchev

Reputation: 100248

Try:

<asp:GridView runat="server" >
    <Columns>
    </Columns>

    <EditRowStyle BackColor="#999999" />    
    <SelectedRowStyle BackColor="#999999" /> 
</asp:GridView>

Upvotes: 1

Kirit Chandran
Kirit Chandran

Reputation: 719

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 = Color.LightYellow;
} 

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

Upvotes: 1

Rami Alshareef
Rami Alshareef

Reputation: 7140

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

Upvotes: 0

Related Questions