电脑故障

位置:IT落伍者 >> 电脑故障 >> 浏览文章

鼠标移到GridView某一行时改变该行的背景色方法


发布日期:2020/6/22
 

效果图

做法

双击GridView的OnRowDataBound事件

在后台的GridView_RowDataBound()方法添加代码最后代码如下所示

protected void GridView_RowDataBound(object sender GridViewRowEventArgs e)

{

int i;

//执行循环保证每条数据都可以更新

for (i = ; i < GridViewRowsCount; i++)

{

//首先判断是否是数据行

if (eRowRowType == DataControlRowTypeDataRow)

{

//当鼠标停留时更改背景色

eRowAttributesAdd(onmouseover c=thisstylebackgroundColor;thisstylebackgroundColor=#AFF);

//当鼠标移开时还原背景色

eRowAttributesAdd(onmouseout thisstylebackgroundColor=c);

}

}

}

前台代码

<html xmlns= >

<head runat=server>

<title>实现鼠标划过改变GridView的行背景色 清清月儿 </title>

</head>

<body>

<form id=form runat=server>

<div>

<asp:GridView ID=GridView runat=server AutoGenerateColumns=False DataKeyNames=身份证号码

DataSourceID=SqlDataSource AllowSorting=True BackColor=White BorderColor=#CCCCCC BorderStyle=None BorderWidth=px CellPadding= FontSize=px OnRowDataBound=GridView_RowDataBound>

<Columns>

<asp:BoundField DataField=身份证号码 HeaderText=身份证号码 ReadOnly=True SortExpression=身份证号码 />

<asp:BoundField DataField=姓名 HeaderText=姓名 SortExpression=姓名 />

<asp:BoundField DataField=家庭住址 HeaderText=家庭住址 SortExpression=家庭住址 />

<asp:BoundField DataField=邮政编码 HeaderText=邮政编码 SortExpression=邮政编码 />

</Columns>

<FooterStyle BackColor=White ForeColor=# />

<RowStyle ForeColor=# />

<SelectedRowStyle BackColor=# FontBold=True ForeColor=White />

<PagerStyle BackColor=White ForeColor=# HorizontalAlign=Left />

<HeaderStyle BackColor=# FontBold=True ForeColor=White />

</asp:GridView>

<asp:SqlDataSource ID=SqlDataSource runat=server ConnectionString=<%$ ConnectionStrings:北风贸易ConnectionString %>

SelectCommand=SELECT top [身份证号码] [姓名] [员工性别] [家庭住址] [邮政编码] FROM [飞狐工作室] DataSourceMode=DataReader></asp:SqlDataSource>

</div>

</form>

</body>

</html>

上一篇:开发手记之实现web.config的快速

下一篇:Lambda表达式的一般应用