Datagridview绑定数据时行变色,数据行自动编号
protected void GridView3_RowDataBound(object sender, GridViewRowEventArgs e)
{
//首先判断是否是数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
//当鼠标停留时更改背景色
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#FFFFFF'");
//当鼠标移开时还原背景色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=#000000");
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
try
{
e.Row.Cells[0].Text = Convert.ToString((int.Parse(indexpage)-1) * pageNumber + e.Row.DataItemIndex + 1); //第一列自动添加序号
…//进行绑定时数据的转换
}
catch (Exception ex)
{
}
}
}
}