1.拖一个gridview控件,添加RowCreated事件代码,如下:
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
e.Row.Attributes.Add("onmouseover", "bgColor='LightCyan'");
e.Row.Attributes.Add("onmouseout", "bgColor=''");
}
2.以上代码变色时连header也随着一起变色,如果只希望datarow变色,加上一个判断即可.
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
//判断是不是datarow,将header去掉
{
e.Row.Attributes.Add("onmouseover", "bgColor='LightCyan'");
e.Row.Attributes.Add("onmouseout", "bgColor=''");
}
}