当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > asp.net GridView和DataList实现鼠标移到行行变色

ASP.NET
asp.net Execl的添加,更新操作实现代码
asp.net 生成曲线图实现代码
从外部的js文件中获取ASPX页面的控件ClientID
asp.net 因为数据库正在使用的解决方法
asp.net Repeater 自递增
asp.net 实现防迅雷等下载工具盗链
ASP.NET封装的SQL数据库访问类
asp.net 通过指定IP地址得到当前的网络上的主机的域名
aspx 服务器架设问题解决
ASP.NET Session使用详解
Asp.net 5种页面转向方法
ASP.NET 用户多次登录的解决方法
ASP.NET下母版页和内容页中的事件发生顺序整理
asp.net 程序性能优化的七个方面 (c#(或vb.net)程序改进)
从客户端检测到有潜在危险的Request.Form值的asp.net代码
asp.net CommunityServer中的wwwStatus
在应用程序级别之外使用注册为allowDefinition=''MachineToApplication''的节是错误的
.net开发人员常犯的错误分析小结
ASP.net Substitution 页面缓存而部分不缓存的实现方法
asp.net 生成静态时的过滤viewstate的实现方法

ASP.NET 中的 asp.net GridView和DataList实现鼠标移到行行变色


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 237 ::
收藏到网摘: n/a

在设计页面添加了DataList控件后,我在使用DataList绑定数据时是通过单元格来绑定的,因此鼠标效果就在源代码页面去实现 在GridView控件的RowDataBound事件里添加以下代码
if (e.Row.RowType == DataControlRowType.DataRow)
{
//当鼠标移到行上时更改背景色
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#EE82EE'");
//当鼠标移开时还原背景色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
在设计页面添加了DataList控件后,我在使用DataList绑定数据时是通过单元格来绑定的,因此鼠标效果就在源代码页面去实现,如下例所示
<asp:DataList ID="DataList1" runat="server" BorderWidth="1" >
<ItemTemplate>
<tr onmouseover="this.style.backgroundColor='#8EC26F'" onmouseout="this.style.backgroundColor=''" >
<td>
<asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ID") %>'></asp:Label>
</td>
<td>
<asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Area") %>'></asp:Label>
</td>
</tr>
</ItemTemplate>
<HeaderTemplate>
Header1</td>
<td>Header2
</HeaderTemplate>
</asp:DataList>