日期:2014-05-18  浏览次数:20535 次

求救~如何写一个有关grideview上鼠标经过变色-写一个.cs的类 能够被全局的gridview调用~
就是想写一个这样的类   就不用每个gridview上都去写同样的代码了

------解决方案--------------------
public class myGridView : System.Web.UI.WebControls.GridView
{
public myGridView ()
{
this.RowDataBound += new EventHandler(myGridView_RowDataBound);
}
protected void myGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)
{
//变色
}
}

}
------解决方案--------------------
自己研究一下:
//隐藏列调用事件
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//实现无刷新取值,无须隐藏列代码
//给活动行添加一个新属性
e.Row.Attributes.Add( "Onclick ", "rowonclick(this) ");
//判断奇偶行,鼠标经过移出时,改变行背景色。
if(e.Row.RowIndex % 2 == 0)
{
e.Row.Attributes.Add( "onmouseover ", "this.style.backgroundColor= 'InactiveCaption ' ");//淡蓝色
   e.Row.Attributes.Add( "onmouseout ", "this.style.backgroundColor= '#EFF3FB ' ");
}
else
{
e.Row.Attributes.Add( "onmouseover ", "this.style.backgroundColor= 'InactiveCaption ' ");//淡蓝色
e.Row.Attributes.Add( "onmouseout ", "this.style.backgroundColor= 'White ' ");
}
}
}