简体   繁体   English

如何在C#Web应用程序的网格中更改所选行的颜色?

[英]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.

相关问题 在ASP.NET C#中更改网格视图的选定行的颜色 - Change the color of the selected row of a grid view in asp.net c# 如何更改 datagridview 选定行的背景颜色? - How do I change the datagridview selected row background color? 在带有HTML表格的网页上,如何确定是否使用C#选择了HTML行? - On a web page with Html Table, how do I determine if a Html Row is selected or not using c#? 选中时更改网格行的背景颜色 - Change Background color of grid row when selected 在c#winforms中从数据库加载数据后,如何在dev express网格中更改行颜色 - how to change row color in dev express grid after the data is loaded from the database in c# winforms 如何在datagridview中更改行的颜色C# - How to change color of row in datagridview c# 使用上下文菜单时如何更改数据网格 WPF C# 中选定行的字体颜色 - How to change font color of selected row in datagrid WPF C# when using context menu 如何使用C#在Excel中更改系列颜色? - How to do I change a Series color in Excel using C#? 如何在c#中更改笔的颜色? - How do I change the color of the pen in c#? c#如何更改特定文本框的颜色为空? - c# How do i change the color of a specific textbox if it is empty?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM