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
Highlighting the Selected Row GridView
提问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 td
the 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>