How to change grid view row color when user mouse move on grid view
.ASPX Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="howtosetgridviewrowcoloronmousemove.aspx.cs" Inherits="howtosetgridviewrowcoloronmousemove" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function MouseOverclr(x) {
oldgridcolor = x.style.backgroundColor;
x.style.backgroundColor = '#ffeb95';
x.style.cursor = 'pointer';
x.style.textDecoration = 'underline';
}
function MouseOutclr(x) {
x.style.backgroundColor = oldgridcolor;
x.style.textDecoration = 'none';
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:GridView ID="GridView1" runat="server"
onrowdatabound="GridView1_RowDataBound" ShowHeader="False">
</asp:GridView>
</form>
</body>
</html>
. .ASPX.CS Code
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
.First add this name space
using System.Drawing;
public partial class howtosetgridviewrowcoloronmousemove : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ArrayList li;
li = new ArrayList();
string[] clrNm = System.Enum.GetNames(typeof(System.Drawing.KnownColor));
FontFamily[] FontnameList = FontFamily.Families;
foreach (FontFamily ff in FontFamily.Families)
{
string fnt;
int ind = ff.ToString().IndexOf('=') + 1;
int rndind = ff.ToString().Length - ind;
fnt = ff.ToString().Substring(ind, rndind - 1);
li.Add(fnt);
}
GridView1.DataSource = li;
GridView1.DataBind();
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add ("onmouseover" , "javascript:MouseOverclr(this)");
e.Row.Attributes.Add ("onmouseout","javascript:MouseOutclr(this)");
}
}
}
0 comments:
Post a Comment