2

enter image description hereI want to change the color of particular row selected in the grid. How is it possible for my web application? Please suggest me.

5 Answers5

0

You have to add some javascript to every row in code-behind. Handle onmouseover event and change background color: Change GridView row color based on condition

Community
  • 1
  • 1
opewix
  • 4,993
  • 1
  • 20
  • 42
0

Attach an onclick javascript function to each checkbox, and upon if the checkbox is checked, then assign some css class to that row, which will highlight the entire row.

Developer
  • 759
  • 2
  • 9
  • 24
0

In your GridView, add the SelectedRowStyle-property and use the BackColor-property to set the color of the selected row.

So your GridView will look like this:

<asp:GridView ID="GridTest" runat="server" DataSourceID=... >
   <Columns>
   ...
   </Columns>
   <SelectedRowStyle BackColor="#E2DED6"/>
</asp:GridView>
Mee
  • 150
  • 4
  • 10
0

If this is a GridView control that we are talking about here, then you can just make use of the <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.

Tim B James
  • 20,084
  • 4
  • 73
  • 103
0

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>
Sonal Satpute
  • 490
  • 3
  • 8