鼠标在DataGrid上移动时触发事件
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace Demos
{
?///
?/// WebForm1 的摘要说明。
?///
?public class mouse : System.Web.UI.Page
?{
??protected System.Web.UI.WebControls.DataGrid Gridaaa;
??protected System.Web.UI.WebControls.DataGrid Gridbbb;
?
??private void Page_Load(object sender, System.EventArgs e)
??{
???Bind();
??}
??#region Web 窗体设计器生成的代码
??override protected void OnInit(EventArgs e)
??{
???//
???// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
???//
???InitializeComponent();
???base.OnInit(e);
??}
??
??///
??/// 设计器支持所需的方法 - 不要使用代码编辑器修改
??/// 此方法的内容。
??///
??private void InitializeComponent()
??{???
???this.Gridaaa.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.Gridaaa_PageIndexChanged);
???this.Gridaaa.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.Gridaaa_ItemDataBound);
???this.Gridbbb.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.Gridbbb_PageIndexChanged);
???this.Gridbbb.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.Gridbbb_ItemDataBound);
???this.Load += new System.EventHandler(this.Page_Load);
??}
??#endregion
??public void Bind()
??{
???Pub.BindSql(aaa.Sel,this.Gridaaa);
???Pub.BindSql(bbb.Sel,this.Gridbbb);
??}
??private void Gridaaa_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
??{
???if(e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem )
???{
????e.Item.Attributes.Add("onmouseover","this.style.backgroundColor='Silver'");
????e.Item.Attributes.Add("onmouseout","this.style.backgroundColor='white'");
???}
??}
??private void Gridbbb_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
??{
???if(e.Item.ItemType==ListItemType.Item? || e.Item.ItemType==ListItemType.AlternatingItem )
???{
????e.Item.Cells[0].Attributes.Add("onmouseover","this.style.backgroundColor='#cccc99'");
????e.Item.Cells[0].Attributes.Add("onmouseout","this.style.backgroundColor='white'");
????//
????e.Item.Cells[0].Style["cursor"] = "hand";
????//
????e.Item.Cells[0].Attributes.Add("onclick", "alert('You click at ID: " +e.Item.Cells[0].Text + "!');");
???}
??}
??private void Gridaaa_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
??{
???this.Gridaaa.CurrentPageIndex=e.NewPageIndex;
???Pub.BindSql(aaa.Sel,this.Gridaaa);
??}
??private void Gridbbb_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
??{
???this.Gridbbb.CurrentPageIndex=e.NewPageIndex;
???Pub.BindSql(bbb.Sel,this.Gridbbb);
??}
?}
}