Highlighting the Selected Row GridView

21,343

Solution 1

here is how i able to fix:

if ((e.Row.RowType == DataControlRowType.DataRow & ((e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit))) {   
         e.Row.BackColor = Drawing.Color.Yellow;   
     }  

Solution 2

Did you try EditRowStyle?

.EditRowStyle
{
    background-color: Yellow;
}

<asp:GridView runat="server" CssClass="DataWebControlStyle">
   <AlternatingRowStyle CssClass="AlternatingRowStyle" />
   <RowStyle CssClass="RowStyle" />
   <HeaderStyle CssClass="HeaderStyle" />
   <EditRowStyle CssClass="EditRowStyle" />
</asp:GridView>

Solution 3

The EditRowStyle class is applied to the <tr> not the <td>. So if you did .SelectedRowStyle td the css would be applied correctly.

This is what I use:

<EditRowStyle CssClass="selectedRowStyle" />

Then CSS

.selectedRowStyle td
{
    background-color: green;
}
Share:
21,343
Nick Kahn
Author by

Nick Kahn

Updated on July 09, 2022

Comments

  • Nick Kahn
    Nick Kahn almost 2 years

    when the user click on Edit from the gridview i want to highlight the row and here is what i have done but no effect. what else i am missing?

    .SelectedRowStyle
    {
        background-color: Yellow;
    }
    
    <asp:GridView runat="server" CssClass="DataWebControlStyle">
       <AlternatingRowStyle CssClass="AlternatingRowStyle" />
       <RowStyle CssClass="RowStyle" />
       <HeaderStyle CssClass="HeaderStyle" />
       <SelectedRowStyle CssClass="SelectedRowStyle" />
    </asp:GridView>
    
  • Nick Kahn
    Nick Kahn over 13 years
    i just tried with editrowstyle but does not highlight the row, may be because of postback?
  • Nick Kahn
    Nick Kahn about 12 years
    Rick, i am sorry for late response but i dont remember exactly where i have added.
  • Neil Knight
    Neil Knight over 11 years
    Probably because the CssClass doesn't relate to the CSS class