asp.net GridView控件鼠标移动某行改变背景颜色(方法一)
作者:
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>
您可能感兴趣的文章:
- ASP.NET 2.0/3.5中直接操作Gridview控件插入新记录
- asp.net GridView控件中模板列CheckBox全选、反选、取消
- asp.net GridView控件中实现全选的解决方案
- ASP.NET2.0中用Gridview控件操作数据的代码
- ASP.NET GridView控件在列上格式化时间及DataFormatString使用
- asp.net的GridView控件使用方法大全
- asp.net中GridView控件遍历的小例子
- Asp.net的GridView控件实现单元格可编辑方便用户使用
- ASP.NET4 GridView的四种排序样式详解
- ASP.NET使用GridView导出Excel实现方法
- asp.net gridview分页:第一页 下一页 1 2 3 4 上一页 最末页
- ASP.NET中为GridView添加删除提示框的方法
- asp.net中GridView数据鼠标移入显示提示信息
- 如何用jQuery实现ASP.NET GridView折叠伸展效果
- ASP.NET GridView中加入RadioButton不能单选的解决方案
- 灵活掌握asp.net中gridview控件的多种使用方法(上)
- 灵活掌握asp.net中gridview控件的多种使用方法(下)