您的位置:首页 > 其它

gridview 鼠标点击行变色 等实现

2014-05-07 10:49 309 查看
<script type="text/javascript">
var prevselitem = null;
function selectx(row) {
if (prevselitem != null) {
prevselitem.style.backgroundColor = '#ffffff';
}
row.style.backgroundColor = '#aaaaaa';
prevselitem = row;
}
</script>


首先在网页的<head>下加上上面的脚本,目的是设置好背景色。

protected void GridView_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事件
}
}


然后在后台加上事件响应,有许多功能。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: