在ASP.NET中实现鼠标移动悬停在DataGrid时高亮显示这一行的方法
来源:互联网 发布:win10运行软件通知 编辑:程序博客网 时间:2024/05/15 15:25
首先在WebFrom页面中添加JavaScript 代码块
为了防止DataGrid标头的滚动,可以在增加这么一个脚本
1<script>
2 //鼠标移动时高亮显示所悬停的行
3 function SetDataGridBackColor(color,isMouseOut)
4 {
5 var tr=event.srcElement.parentElement;
6
7 var iRowIndex = tr.rowIndex ;
8 if( isMouseOut )
9 {
10 if( ( iRowIndex % 2 ) == 1 )
11 {
12 tr.style.backgroundColor = color;
13 }
14 else
15 {
16 tr.style.backgroundColor = "#EAE9D7";
17 }
18 }
19 else
20 {
21 tr.style.backgroundColor = color;
22 }
23 }
24 </script>
然后在aspx文件中的DataGrid事件中去注册这个脚本2 //鼠标移动时高亮显示所悬停的行
3 function SetDataGridBackColor(color,isMouseOut)
4 {
5 var tr=event.srcElement.parentElement;
6
7 var iRowIndex = tr.rowIndex ;
8 if( isMouseOut )
9 {
10 if( ( iRowIndex % 2 ) == 1 )
11 {
12 tr.style.backgroundColor = color;
13 }
14 else
15 {
16 tr.style.backgroundColor = "#EAE9D7";
17 }
18 }
19 else
20 {
21 tr.style.backgroundColor = color;
22 }
23 }
24 </script>
private void dgTemp_PreRender(object sender, System.EventArgs e)
{
for (int i = 0 ; i < dgTemp.Items.Count; i++)
{
dgTemp.Items[i].Attributes.Add("onmouseover","SetDataGridBackColor('LightBlue',false);");
dgTemp.Items[i].Attributes.Add("onmouseout","SetDataGridBackColor('white',true);");
}
}
{
for (int i = 0 ; i < dgTemp.Items.Count; i++)
{
dgTemp.Items[i].Attributes.Add("onmouseover","SetDataGridBackColor('LightBlue',false);");
dgTemp.Items[i].Attributes.Add("onmouseout","SetDataGridBackColor('white',true);");
}
}
为了防止DataGrid标头的滚动,可以在增加这么一个脚本
private void dgTemp_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//使DataGrid标头不滚动
if (e.Item.ItemType == ListItemType.Header)
{
e.Item.Style.Add("position","relative;top:expression(document.all['dgBHGJBSZ'].offsetParent.scrollTop);");
}
}
{
//使DataGrid标头不滚动
if (e.Item.ItemType == ListItemType.Header)
{
e.Item.Style.Add("position","relative;top:expression(document.all['dgBHGJBSZ'].offsetParent.scrollTop);");
}
}
链接地址: http://Arthur1999.cnblogs.com/archive/2006/07/14/450487.html
- 在ASP.NET中实现鼠标移动悬停在DataGrid时高亮显示这一行的方法
- 在ASP.NET中实现鼠标移动悬停在DataGrid时高亮显示这一行的方法
- 实现鼠标悬停高亮显示---分别在gridview和datagrid中
- 实现鼠标悬停高亮显示---分别在gridview和datagrid中
- 在asp.net中实现datagrid checkbox 全选的方法
- 使用CSS实现鼠标悬停在一行上,显示某些元素
- 在ASP 中实现ASP.Net 的DataGrid 功能
- asp.net的DataGrid中在每行依次显示序号的方法
- 在ASP.NET中如何在DataGrid中实现数据嵌套显示
- asp.net(c#) GridView实现鼠标悬停高亮显示
- asp.net(c#)GridView实现鼠标悬停高亮显示
- 在Web窗体的DataGrid控件实现鼠标悬停被选中样式
- 用WPF实现在LISTVIEW中的鼠标悬停TOOLTIP显示
- ASP.NET:在DataGrid中显示下拉列表框
- ASP.NET数据库内容在DATAGRID显示
- 在ASP 中实现ASP.Net 的DataGrid 功能(转载)
- ASP.NET中DataGrid在JSP中的实现
- 在salesforce中实现鼠标悬停显示提示框效果,并对显示框内容进行微缩页面布局
- [转]dw的默认文档类型(识别ftl为html文档)
- 如何使显示的中英文转90度_Sandy33解决
- 绿色SQL Server原理(12)枚举SQLServer 标准登录账号列表
- Porting QT/E & QPE to VT8420
- 西坝豆腐
- 在ASP.NET中实现鼠标移动悬停在DataGrid时高亮显示这一行的方法
- 有高手吗?--javascipt
- Web Service的几个很重要的概念
- 对称EDS加解密方法
- ASP_NET下使用MD5加密
- Windows系统编程之异步I/O和完成端口[转]
- 改善用户体验的技术-动态缓冲
- Defeating the Hacker : A Non-Technical Guide to Computer Security
- 用户控件触发事件