I want to change the color of particular row selected in the grid. How is it possible for my web application? Please suggest me.
Asked
Active
Viewed 1.1k times
2

Vinit Kumar Kamboj
- 73
- 1
- 2
- 7
-
How you are selecting your row.Is it a Select Event of a Gridview? – RL89 Sep 13 '12 at 08:02
-
I tried it with DataControlRowType but its not working – Vinit Kumar Kamboj Sep 13 '12 at 08:06
-
you need to use RowCreated-Event of the GridView. I think you need something like [this][1] [1]: http://stackoverflow.com/questions/6250545/how-to-implement-full-row-selecting-in-gridview-without-select-button – Mohamed Farrag Sep 13 '12 at 08:21
-
http://www.aspsnippets.com/Articles/Using-JavaScript-with-ASP.Net-GridView-Control.aspx – 4b0 Sep 13 '12 at 08:28
5 Answers
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
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
-
Kemboj - you need to also set the Selected Row index in your RowCommand. – Tim B James Sep 13 '12 at 09:30
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
-
are you getting any error. its working for me. you need to add the reference for jQuery – Sonal Satpute Sep 13 '12 at 09:25