鼠标移动DataGrid控件某行改变该行的背景
2006-11-08 17:35
423 查看
在DataGrid控件的数据项的Attributes属性为数据项添加Javascript脚本即可
(1) 触发onmouseover事件时,执行如下代码设置当前DataGrid项的背景色
thiscolor = this.style.backgroundColor,this.style.backgroundColor='#ddf3ff'
(2) 当触发onmouseout事件时,执行如下代码还原前面的背景色
this.style.backgroundColor = thiscolor
在DataGrid控件的ItemDataBound事件
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//如果当前项不为空
if(e.Item.ItemIndex != -1)
{
//取得当前索引值加1,因为索引是从0开始,给DataGrid自动编号
int orderID = e.Item.ItemIndex +1;
e.Item.Cells[1].Text = orderID.ToString();
}
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onmouseover","thiscolor = this.style.backgroundColor,this.style.backgroundColor='#ddf3ff'
");
e.Item.Attributes.Add("onmouseout"," this.style.backgroundColor = thiscolor
");
}
}
(1) 触发onmouseover事件时,执行如下代码设置当前DataGrid项的背景色
thiscolor = this.style.backgroundColor,this.style.backgroundColor='#ddf3ff'
(2) 当触发onmouseout事件时,执行如下代码还原前面的背景色
this.style.backgroundColor = thiscolor
在DataGrid控件的ItemDataBound事件
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//如果当前项不为空
if(e.Item.ItemIndex != -1)
{
//取得当前索引值加1,因为索引是从0开始,给DataGrid自动编号
int orderID = e.Item.ItemIndex +1;
e.Item.Cells[1].Text = orderID.ToString();
}
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onmouseover","thiscolor = this.style.backgroundColor,this.style.backgroundColor='#ddf3ff'
");
e.Item.Attributes.Add("onmouseout"," this.style.backgroundColor = thiscolor
");
}
}
相关文章推荐
- asp.net GridView控件鼠标移动某行改变背景颜色(方法一)
- js 当鼠标移动到表格一行上时,该行背景颜色改变
- asp.net GridView控件鼠标移动某行改变背景颜色(方法一)
- 当鼠标移动到GridView控件上某行时,该行的颜色改变(GridView行变色)
- 如何实现鼠标移到DataGrid控件的某一行时改变该行的背景
- 实现 鼠标移动到表格的某行 该行换背景 ---myEclipse编写
- MFC在鼠标自定义的一定的范围内实现拖动窗口移动、错误:不支持尝试执行的操作、实现进度条颜色的渐变或者背景和前景色的改变
- 表格:增加、删除行,鼠标移动改变行背景色,行内文本框自适应td,a除下划线(使用节点实现)
- 当鼠标移动到表格的一行时这一行的背景颜色发生改变
- 表格,鼠标移到,移出某行,改变该行样式JS
- C#在DataGridView当鼠标移到某行时,该行改变颜色
- 7.鼠标移到GridView某一行时改变该行的背景色方法二:
- 鼠标移到GridView某一行时改变该行的背景色方法二
- 鼠标移到GridView某一行时改变该行的背景色方法二
- css如何做到 鼠标移动到超链接时,超链接会发生改变,例如改变颜色、字体大小、背景颜色等
- js控制鼠标移动到表格的某一行时改变该行的背景色
- 鼠标移动 改变Datagrid行的背景颜色
- 鼠标移到GridView某一行时改变该行的背景色方法二
- table鼠标移动背景,边框颜色改变
- ASP.NET基础教程-DataGrid表格控件-利用ItemDataBound事件实现鼠标移动到控件的某一行时改变该行的背景色