首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

gridview 行背景颜色改变如何做呀

2012-09-11 
gridview 行背景颜色改变怎么做呀鼠标放上去,行背景颜色改变,离开变回原来的[解决办法]用jquery,给你找找j

gridview 行背景颜色改变怎么做呀
鼠标放上去,行背景颜色改变,离开变回原来的

[解决办法]
用jquery,给你找找

js:
用jquery,
给你找找

<script>
var bgclr;
function mouseOver(obj){
 bgclr=$(obj).css("background-color");
 $(obj).css("background-color","red");
}

function mouseOut(obj){
 $(obj).css("background-color",bgclr);


</script>

cs:

cs:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onMouseOver", "mouseOver(this)");
e.Row.Attributes.Add("onMouseOut", "mouseOut(this)");

}


}


[解决办法]
楼上是用js实现,写在前台页面.
以下是写在后台的代码(gridview事件):
protected void GridView1_RowDataBound(object sender,GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// e.Row.Attributes.Add("onmouseover", "if(this!=prevselitem){this.style.backgroundColor='#Efefef'}");//当鼠标停留时更改背景色
// e.Row.Attributes.Add("onmouseout", "if(this!=prevselitem){this.style.backgroundColor='#ffffff'}");//当鼠标移开时还原背景色
e.Row.Attributes.Add("onclick", e.Row.ClientID.ToString() + ".checked=true;selectx(this)");//点击行变色

//e.Row.Attributes["style"] = "Cursor:hand"; //设置悬浮鼠标指针形状为"小手"
// GridView1.HeaderRow.Cells[10].Visible = false;
// e.Row.Cells[10].Visible = false;//隐藏选择按钮
//String evt = Page.ClientScript.GetPostBackClientHyperlink(sender as System.Web.UI.WebControls.GridView, "Select$" + e.Row.RowIndex.ToString());
// e.Row.Attributes.Add("onclick", evt);//执行选择行GridView1_SelectedIndexChanged事件
}
}

热点排行