在DataGrid_DataItemBound()事件中,
e.Attributes.Add("onmouseover","设置不同的背景色");
e.Attributes.Add("onmouseover","设置不同的背景色");
解决方案 »
- JS复选框默认选择数据库中的值
- UserControl的问题
- |zyciis| 为什么多线程的过程,不能传参 急 谢谢
- 对 Bind 的调用格式不正确。
- 点击分页的数字后,gridview不见了...
- 跪求.net 下nVelocity用户手册(中文)
- 鼠标拖动控件
- 邮件附件是存放在服务器目录下还是数据库下好?
- 请问:using Microsoft.Office.Interop.Excel;这个引用是需要调用那个com?在那里可以下到?
- CompareValidator 居然不能验证 "$12,345.35" 这样的 Currency 内容!已将区域设置改成 USA
- junix???
- 求SQL语句!
<table>
<tr onmouseover="this.style.backgroundColor='Silver'" onmouseout="this.style.backgroundColor='white'"><td>...</td></tr>
</table>
这是从客户端看到的脚本那么我们可以通过datagrd在绑定数据的ItemDataBound事件时候将这段脚本加入进去。具体代码如下:
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem){
e.Item.Attributes.Add("onmouseover","this.style.backgroundColor='Silver'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor='white'");
}
这样就可以让鼠标移动过行的时候将颜色变成silver移走之后变成white(本色)。
前面的判断可以排除鼠标移动到Head和Foot的时候也有相同的效果,这样可以把脚本只产生在里面的项上。或者指定某列变色:
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem){
e.Item.Cells[2].Attributes.Add("onmouseover","this.style.backgroundColor='Silver'");
e.Item.Cells[2].Attributes.Add("onmouseout","this.style.backgroundColor='white'");
}不但如此你还可以指定鼠标移动到某一列时鼠标的形状:
e.Item.Cells[3].Style("cursor") = "hand"
或者点击某一个单元个显示提示信息:
e.Item.Cells[3].Attributes.Add("onclick", "alert('你点击的ID是: " + e.Item.Cells[0].Text + "!');")
等等...通过这个方法我们还可以添加在鼠标移动到行上出现提示的效果
e.Item.Cells[2].Attributes.Add("title","在这里可以添加提示信息");
e.Item.Attributes.Add("onmouseover","设置不同的背景色");