CSS 突出显示选定行 GridView

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4812203/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 23:34:03  来源:igfitidea点击:

Highlighting the Selected Row GridView

asp.netcssgridview

提问by Nick Kahn

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?

当用户从 gridview 单击 Edit 时,我想突出显示该行,这是我所做的但没有效果。我还缺少什么?

.SelectedRowStyle
{
    background-color: Yellow;
}

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

采纳答案by Nick Kahn

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;   
     }  

回答by Chase Florell

Did you try EditRowStyle?

你试了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>

回答by Steve

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

该EditRowStyle类应用到<tr>不是<td>。因此,如果您这样做,.SelectedRowStyle td则 css 将被正确应用。

This is what I use:

这是我使用的:

<EditRowStyle CssClass="selectedRowStyle" />

Then CSS

然后CSS

.selectedRowStyle td
{
    background-color: green;
}

回答by Kanchan Dey

May be this line of code help you:

可能这行代码可以帮助您:

.DataWebControlStyle tr:hover
{
    background-color: Yellow;
}

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