在ASP.NET中实现鼠标移动悬停在DataGrid时高亮显示这一行的方法
2006-07-14 16:18
1156 查看
首先在WebFrom页面中添加JavaScript 代码块
//鼠标移动时高亮显示所悬停的行
function SetDataGridBackColor(color,isMouseOut)
{
var tr=event.srcElement.parentElement;
var iRowIndex = tr.rowIndex ;
if( isMouseOut )
{
if( ( iRowIndex % 2 ) == 1 )
{
tr.style.backgroundColor = color;
}
else
{
tr.style.backgroundColor = "#EAE9D7";
}
}
else
{
tr.style.backgroundColor = color;
}
}
//鼠标移动时高亮显示所悬停的行
function SetDataGridBackColor(color,isMouseOut)
{
var tr=event.srcElement.parentElement;
var iRowIndex = tr.rowIndex ;
if( isMouseOut )
{
if( ( iRowIndex % 2 ) == 1 )
{
tr.style.backgroundColor = color;
}
else
{
tr.style.backgroundColor = "#EAE9D7";
}
}
else
{
tr.style.backgroundColor = color;
}
}
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>
//鼠标移动时高亮显示所悬停的行
function SetDataGridBackColor(color,isMouseOut)
{
var tr=event.srcElement.parentElement;
var iRowIndex = tr.rowIndex ;
if( isMouseOut )
{
if( ( iRowIndex % 2 ) == 1 )
{
tr.style.backgroundColor = color;
}
else
{
tr.style.backgroundColor = "#EAE9D7";
}
}
else
{
tr.style.backgroundColor = color;
}
}
//鼠标移动时高亮显示所悬停的行
function SetDataGridBackColor(color,isMouseOut)
{
var tr=event.srcElement.parentElement;
var iRowIndex = tr.rowIndex ;
if( isMouseOut )
{
if( ( iRowIndex % 2 ) == 1 )
{
tr.style.backgroundColor = color;
}
else
{
tr.style.backgroundColor = "#EAE9D7";
}
}
else
{
tr.style.backgroundColor = color;
}
}
//鼠标移动时高亮显示所悬停的行
function SetDataGridBackColor(color,isMouseOut)
{
var tr=event.srcElement.parentElement;
var iRowIndex = tr.rowIndex ;
if( isMouseOut )
{
if( ( iRowIndex % 2 ) == 1 )
{
tr.style.backgroundColor = color;
}
else
{
tr.style.backgroundColor = "#EAE9D7";
}
}
else
{
tr.style.backgroundColor = color;
}
}
//鼠标移动时高亮显示所悬停的行
function SetDataGridBackColor(color,isMouseOut)
{
var tr=event.srcElement.parentElement;
var iRowIndex = tr.rowIndex ;
if( isMouseOut )
{
if( ( iRowIndex % 2 ) == 1 )
{
tr.style.backgroundColor = color;
}
else
{
tr.style.backgroundColor = "#EAE9D7";
}
}
else
{
tr.style.backgroundColor = color;
}
}
然后在aspx文件中的DataGrid事件中去注册这个脚本
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);");
}
}
为了防止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);");
}
}
链接地址: http://Arthur1999.cnblogs.com/archive/2006/07/14/450487.html
//鼠标移动时高亮显示所悬停的行
function SetDataGridBackColor(color,isMouseOut)
{
var tr=event.srcElement.parentElement;
var iRowIndex = tr.rowIndex ;
if( isMouseOut )
{
if( ( iRowIndex % 2 ) == 1 )
{
tr.style.backgroundColor = color;
}
else
{
tr.style.backgroundColor = "#EAE9D7";
}
}
else
{
tr.style.backgroundColor = color;
}
}
//鼠标移动时高亮显示所悬停的行
function SetDataGridBackColor(color,isMouseOut)
{
var tr=event.srcElement.parentElement;
var iRowIndex = tr.rowIndex ;
if( isMouseOut )
{
if( ( iRowIndex % 2 ) == 1 )
{
tr.style.backgroundColor = color;
}
else
{
tr.style.backgroundColor = "#EAE9D7";
}
}
else
{
tr.style.backgroundColor = color;
}
}
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>
//鼠标移动时高亮显示所悬停的行
function SetDataGridBackColor(color,isMouseOut)
{
var tr=event.srcElement.parentElement;
var iRowIndex = tr.rowIndex ;
if( isMouseOut )
{
if( ( iRowIndex % 2 ) == 1 )
{
tr.style.backgroundColor = color;
}
else
{
tr.style.backgroundColor = "#EAE9D7";
}
}
else
{
tr.style.backgroundColor = color;
}
}
//鼠标移动时高亮显示所悬停的行
function SetDataGridBackColor(color,isMouseOut)
{
var tr=event.srcElement.parentElement;
var iRowIndex = tr.rowIndex ;
if( isMouseOut )
{
if( ( iRowIndex % 2 ) == 1 )
{
tr.style.backgroundColor = color;
}
else
{
tr.style.backgroundColor = "#EAE9D7";
}
}
else
{
tr.style.backgroundColor = color;
}
}
//鼠标移动时高亮显示所悬停的行
function SetDataGridBackColor(color,isMouseOut)
{
var tr=event.srcElement.parentElement;
var iRowIndex = tr.rowIndex ;
if( isMouseOut )
{
if( ( iRowIndex % 2 ) == 1 )
{
tr.style.backgroundColor = color;
}
else
{
tr.style.backgroundColor = "#EAE9D7";
}
}
else
{
tr.style.backgroundColor = color;
}
}
//鼠标移动时高亮显示所悬停的行
function SetDataGridBackColor(color,isMouseOut)
{
var tr=event.srcElement.parentElement;
var iRowIndex = tr.rowIndex ;
if( isMouseOut )
{
if( ( iRowIndex % 2 ) == 1 )
{
tr.style.backgroundColor = color;
}
else
{
tr.style.backgroundColor = "#EAE9D7";
}
}
else
{
tr.style.backgroundColor = color;
}
}
然后在aspx文件中的DataGrid事件中去注册这个脚本
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);");
}
}
为了防止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);");
}
}
链接地址: http://Arthur1999.cnblogs.com/archive/2006/07/14/450487.html
相关文章推荐
- asp.net(c#)GridView实现鼠标悬停高亮显示
- asp.net(c#)GridView实现鼠标悬停高亮显示
- ASP.NET基础教程-DataGrid表格控件-利用ItemDataBound事件实现鼠标移动到控件的某一行时改变该行的背景色
- asp.net(c#)GridView实现鼠标悬停高亮显示
- asp.net(c#) GridView实现鼠标悬停高亮显示
- 实现鼠标悬停高亮显示---分别在gridview和datagrid中
- asp.net鼠标悬停显示信息的方法
- 实现鼠标悬停高亮显示---分别在gridview和datagrid中
- MFC CListBox 鼠标移动到一行就显示高亮的方法代码
- 在ASP.NET的DataGrid中,鼠标点击某行进行高亮显示的解决方案
- 实现鼠标悬停高亮显示---分别在gridview和datagrid中
- ASP.NET 当GridView中没有数据的时候,显示标题栏 并且给出一行数据提示 (两种方法)
- 在asp.net中实现datagrid checkbox 全选的方法
- ASP.NET MVC Bootstrap模板选中菜单高亮显示当前项方法
- C# ASP.NET 最常用的通用权限的3个方法例子展示(每个功能一行代码实现)
- Asp.Net 无刷新文件上传并显示进度条的实现方法及思路
- asp.net下用js实现鼠标移至小图,自动显示相应大图
- asp.net DataGrid实现分页显示数据
- asp.net异步获取datatable并显示的实现方法
- [转]asp.net(c#) datelist DataGrid 中截取字符串加"..." 和 鼠标放上去字符全部显示