日期:2014-05-17  浏览次数:20414 次

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事件
}
}