当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > asp.net GridView控件鼠标移动某行改变背景颜色(方法一)

ASP.NET
在ASP.NET中自动给URL加上超级链接
在ASP.NET中怎么用Session判断用户是否登录?
C#是一种新的语言?或者仅仅只是Java
在网页中动态的生成一个图片
C#实现的18位身份证格式验证算法
Asp.net中的页面乱码的问题
ASP.NET中利用存储过程实现模糊查询
ASP.NET 2.0中构造个性化网页
.net教程:ASP.NET GridView的分页功能
ASP.Net中无刷新执行Session身份验证
用事实说话!AJAX应用程序开发七宗罪
迁移你的Web页面到ASP.NET AJAX 1.0
SQL Server 2005中插入XML数据方法
编程技巧 用Asp.net动态生成html页面
在asp.net 2.0 中使用的存储过程解析
用 asp.net 动态设置 WebService 引用
新手入门之ASP.NET2.0中的缓存技术解析
asp.net编程中实现 MD5 加密
ASP.NET备份恢复SqlServer数据库
Asp.Net输出数据到EXCEL表格中

ASP.NET 中的 asp.net GridView控件鼠标移动某行改变背景颜色(方法一)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 97 ::
收藏到网摘: n/a

asp.net GridView控件鼠标移动某行改变背景颜色
复制代码 代码如下:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Demo19 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
BindData();
}
}
public void BindData()
{
string strSql = "select UserID,C_Name,E_Name,UpdataDate,QQ from Demo_User ";
DataTable dt = SqlHelper.ExecuteDataset(SqlHelper.CONN_STRING, CommandType.Text, strSql, null).Tables[0];
GridView.DataSource = dt;
GridView.DataKeyNames = new string[] { "UserID" };//主键
GridView.DataBind();
}
protected void GridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView.PageIndex = e.NewPageIndex;
BindData();
}
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠标经过时,行背景色变
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#00A9FF'");
//鼠标移出时,行背景色变
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
}
}
}
<table align="center" bgcolor="#c0de98" border="0" cellpadding="0" cellspacing="1" width="99%">
<tr>
<th colspan="2">
GridView演示</th>
</tr>
<tr>
<td colspan="2" style="width: 100%;" >
<asp:GridView ID="GridView" runat="server" Width="100%" AutoGenerateColumns="False" AllowPaging="True" OnPageIndexChanging="GridView_PageIndexChanging" PageSize="12" OnRowDataBound="GridView_RowDataBound" >
<Columns>
<asp:BoundField DataField="UserID" HeaderText="UserID" />
<asp:BoundField DataField="C_Name" HeaderText="中文名字" />
<asp:BoundField DataField="E_Name" HeaderText="英文名字" />
<asp:BoundField DataField="QQ" HeaderText="QQ" />
<asp:BoundField DataField="UpdataDate" HeaderText="更新时间" />
</Columns>
<RowStyle HorizontalAlign="Center" />
<PagerStyle HorizontalAlign="Right" />
</asp:GridView>
</td>
</tr>
</table>