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

ASP.NET
Asp.Net使用POST方法最简单的实现
实现.NET应用程序的自动更新
优秀ASP.NET程序员修炼之路
ASP.NET中实现模板页
在ASP.Net 2.0中实现多语言界面的方法
小议优化ASP.NET应用性能之Cache篇
.net开发投票机的思路
浅析CMS内容管理系统的两种方案
ASP.NET 2.0中动态修改页面标题
“您无权查看该网页”的原因和解决方法
将一个图片按比例缩放显示在一个Frame中
编程使用资源文件实现多语言页面(In Action)
.Net编程的多个小技巧
asp.net2.0学习历程-菜鸟到中级程序员的飞跃
asp.net如何连接sql server2000数据库
FCKeditor 2.6在ASP.NET中的配置方法
使用ASP.NET开发移动通讯的几种方法
ASP.NET 2.0的URL映射的实现方法
如何在Asp.net中使用HtmlArea编辑器
ASP.NET 2.0 中实现跨页提交

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 96 ::
收藏到网摘: 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>