Mouse hover to select a row form ListView
2010-10-08
On a ListView you can add this functionality directly on the row, something like this:
<asp:ListView ID="ListView3" runat="server">
<ItemTemplate>
<tr onmouseover="this.oldClass=this.className;this.className='hover';" onmouseout="this.className=this.oldClass;" onclick='<%# Page.ClientScript.GetPostBackClientHyperlink(gdvBuildings, "Select$" + Container.DataItemIndex.ToString()) %>' >
<td>
<asp:Label ID="Label7" runat="server" Text='<%# Eval("ClientNumber") %>' />
</td>
<td>
<asp:Label ID="CityNameLabel" runat="server" Text='<%# Eval("FullName") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
If you are using GridView, use the following code:
use to OnRowDataBound event and do something like this
e.Row.Attributes["onmouseover"] = "this.oldClass=this.className;this.className='hover';";
e.Row.Attributes["onmouseout"] = "this.className=this.oldClass;";
e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(gdvBuildings, "Select$" + e.Row.RowIndex.ToString());
Above code from stackoverflow