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事件 } }
然后在后台加上事件响应,有许多功能。
相关文章推荐
- windows下用eclipse+goclipse插件+gdb搭建go语言开发调试环境
- 深入Java集合学习系列:HashSet的实现原理
- Android平行排列带图标按钮中的图标不被拉伸布局
- 滑稽,古指谓能言善辩,言辞流利,现在一般都指言语、动作或事态令人发笑。
- pcap文件解析(二)--初识IP包
- 关于iOS沙盒路径问题
- 树dp (至少砍掉几个树枝,能得到有m个结点的子树)
- 自己训练SVM分类器进行HOG行人检测
- linux查看某端口是否被占用
- 按回车键 组件与服务器进行提交
- C++出错提示英汉对照表
- 基于ASP.NET WPF技术及MVP模式实战太平人寿客户管理项目开发(Repository模式)
- poj1556 The Doors
- 2013级C++第11周(春)项目——通过继承拥有基类的资源 【项目1 - 存储班长信息的学生类】
- JQuery一些常见用法与技巧
- xml文件处理
- 样式最常用的命名规则
- JavaScript跨域总结与解决办法
- 串口通信程序中十六进制格式发送和接收实现
- vagrant 使用