gridview 鼠标移动 换色 参考:http://www.cnblogs.com/insus/articles/1411057.html 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 写过 但是没放在ModalPopupExtender和panel过·· protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e) { //加入鼠标滑过的高亮效果 if (e.Row.RowType == DataControlRowType.DataRow)//判定当前的行是否属于datarow类型的行 { //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#9999ff',this.style.fontWeight='';"); //当鼠标离开的时候 将背景颜色还原的以前的颜色 e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';"); } //单击行改变行背景颜色 if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add("onclick", "this.style.backgroundColor='#99cc00'; this.style.color='buttontext';this.style.cursor='default';"); } } 那就用JS试试看protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes["onMouseOver"] = "js.ItemOver(this)"; } } 页面上加<SCRIPT language=javascript type=text/javascript> var js=new function(){ if (!objbeforeItem){var objbeforeItem=null;var objbeforeItembackgroundColor=null;} this.ItemOver=function(obj) { if(objbeforeItem){objbeforeItem.style.backgroundColor = objbeforeItembackgroundColor;} objbeforeItembackgroundColor = obj.style.backgroundColor; objbeforeItem = obj; obj.style.backgroundColor = "#00A9FF"; } } </SCRIPT> 或者protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add("onMouseOver", "SetNewColor(this);"); e.Row.Attributes.Add("onMouseOut", "SetOldColor(this);"); } } 页面上加入<SCRIPT language=javascript> var _oldColor; function SetNewColor(source) { _oldColor=source.style.backgroundColor; source.style.backgroundColor='#00A9FF; } function SetOldColor(source) { source.style.backgroundColor=_oldColor; } </SCRIPT> 我推荐你还是不要用gridview了,它自己生成一堆table代码 protected void GridView1_PreRender1(object sender, EventArgs e) { for (int i = 0; i < GridView1.Rows.Count; i++) //获取表示 GridView 控件中数据行的 GridViewRow 对象的集合。 //GridViewRowCollection 类用于存储和管理 GridView 控件中的 GridViewRow 对象的集合. //一个 GridViewRowCollection,包含 GridView 控件中的所有数据行。 // GridViewRow的 公共属性 Attributes { GridView1.Rows[i].Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#FFFFCC';"); GridView1.Rows[i].Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor;"); } } protected void gvOrder_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add("onmousemove", "movecolor(this)"); e.Row.Attributes.Add("onmouseout", "outcolor(this)"); } }这是这样用的,结果是可以的! 估计ModalPopupExtender中用到了鼠标事件,所以你写在控件中的鼠标事件被重置,无效 这个可以,我亲自测试过:protected void gvDemo_RowDataBound(object sender, GridViewRowEventArgs e){ if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add("onmouseover","currentcolor=this.style.backgroundColor;this.style.backgroundColor='#6699ff' "); e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor"); }} //后台if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add("onmouseover", "onmouse(this)"); e.Row.Attributes.Add("onmouseout", "outmouse(this)"); }//源 <script language="javascript" type="text/javascript"> var cru; function onmouse(object) { cru=object.style.backgroundColor; object.style.backgroundColor="#ff9900"; } function outmouse(object) { object.style.backgroundColor=cru; } </script> 单独放在panel里面没有问题的,再加个上那个就没用过了 请问什么是URL重写呀 求个正则表达式,有参考资料! 怎么能设置WebPart中的TitleUrl的target属性呢?? 下载文本文件后,页面不响应任何操作。报javascript error,对象拒绝访问。 我要在现在的项目上添加其它项目的用户控件,请问怎样做? 大家帮忙一下,怎么可以获得DataSet中的索引值,谢谢! linq 表达式问题 Asp.net连接oracle的程序,经常出现close_wait状态 为什么有没有www都能访问?还有为什么session还不能通用? C#里怎么把"号读入字符变量? sqlserver连接问题 请教!!!
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
//加入鼠标滑过的高亮效果
if (e.Row.RowType == DataControlRowType.DataRow)//判定当前的行是否属于datarow类型的行
{
//当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#9999ff',this.style.fontWeight='';");
//当鼠标离开的时候 将背景颜色还原的以前的颜色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
}
//单击行改变行背景颜色
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", "this.style.backgroundColor='#99cc00'; this.style.color='buttontext';this.style.cursor='default';");
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onMouseOver"] = "js.ItemOver(this)";
}
}
页面上加<SCRIPT language=javascript type=text/javascript>
var js=new function(){
if (!objbeforeItem){var objbeforeItem=null;var objbeforeItembackgroundColor=null;}
this.ItemOver=function(obj)
{
if(objbeforeItem){objbeforeItem.style.backgroundColor = objbeforeItembackgroundColor;}
objbeforeItembackgroundColor = obj.style.backgroundColor;
objbeforeItem = obj;
obj.style.backgroundColor = "#00A9FF";
}
}
</SCRIPT> 或者
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onMouseOver", "SetNewColor(this);");
e.Row.Attributes.Add("onMouseOut", "SetOldColor(this);");
}
}
页面上加入
<SCRIPT language=javascript>
var _oldColor;
function SetNewColor(source)
{
_oldColor=source.style.backgroundColor;
source.style.backgroundColor='#00A9FF;
}
function SetOldColor(source)
{
source.style.backgroundColor=_oldColor;
}
</SCRIPT>
{
for (int i = 0; i < GridView1.Rows.Count; i++)
//获取表示 GridView 控件中数据行的 GridViewRow 对象的集合。
//GridViewRowCollection 类用于存储和管理 GridView 控件中的 GridViewRow 对象的集合.
//一个 GridViewRowCollection,包含 GridView 控件中的所有数据行。
// GridViewRow的 公共属性 Attributes
{
GridView1.Rows[i].Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#FFFFCC';"); GridView1.Rows[i].Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor;");
}
}
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmousemove", "movecolor(this)");
e.Row.Attributes.Add("onmouseout", "outcolor(this)"); }
}这是这样用的,结果是可以的!
protected void gvDemo_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover","currentcolor=this.style.backgroundColor;this.style.backgroundColor='#6699ff' "); e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
}
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "onmouse(this)");
e.Row.Attributes.Add("onmouseout", "outmouse(this)");
}
//源
<script language="javascript" type="text/javascript">
var cru;
function onmouse(object)
{
cru=object.style.backgroundColor;
object.style.backgroundColor="#ff9900";
}
function outmouse(object)
{
object.style.backgroundColor=cru;
}
</script>