[英]How do I change color of selected Row in the Grid in C# web application?
I want to change the color of particular row selected in the grid.
我想更改网格中选定的特定行的颜色。 How is it possible for my web application?
我的Web应用程序怎么可能? Please suggest me.
请给我建议。
You have to add some javascript to every row in code-behind. 您必须在代码隐藏的每一行中添加一些javascript。 Handle onmouseover event and change background color: Change GridView row color based on condition
处理onmouseover事件并更改背景颜色: 根据条件更改GridView行颜色
在每个复选框上附加一个onclick javascript函数,然后选中该复选框,然后为该行分配一些CSS类,这将突出显示整个行。
In your GridView, add the SelectedRowStyle-property and use the BackColor-property to set the color of the selected row. 在GridView中,添加SelectedRowStyle属性,并使用BackColor属性设置所选行的颜色。
So your GridView will look like this: 因此,您的GridView将如下所示:
<asp:GridView ID="GridTest" runat="server" DataSourceID=... >
<Columns>
...
</Columns>
<SelectedRowStyle BackColor="#E2DED6"/>
</asp:GridView>
If this is a GridView
control that we are talking about here, then you can just make use of the <SelectedRowStyle>
如果这是我们在这里讨论的
GridView
控件,那么您可以使用<SelectedRowStyle>
<asp:GridView id="GridView1" runat="Server">
<Columns></Columns>
<SelectedRowStyle CssClass="selectedRowStyle" BackColor="LightCyan"
ForeColor="DarkBlue"
Font-Bold="true" />
</asp:GridView>
Style this up accordingly. 相应地设置样式。
try this 尝试这个
<style type="text/css">
.row-highlight
{
background-color: Yellow;
}
.row-select
{
background-color: red;
}
</style>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<script type="text/javascript">
$(function () {
var tr = $('#<%= GridView1.ClientID %>').find('tr');
tr.hover(
function () { // mouseover
$(this).addClass('row-highlight');
},
function () { // mouseout
$(this).removeClass('row-highlight');
}
);
tr.click(function() {
$(this).addClass('row-select');
});
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.