鼠标移到或移开gridview上改变背景色
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
int num = GridView1.PageIndex + 1;
Label1.Text = "第" + num + "页/共" + GridView1.PageCount + "页";
if (e.Row.RowIndex != -1)
{
int indexID = this.GridView1.PageIndex * this.GridView1.PageSize + e.Row.RowIndex + 1;
e.Row.Cells[0].Text = indexID.ToString();
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "if(this!=prevselitem){this.style.backgroundColor='#Efefef'}");//当鼠标停留时更改背景色
e.Row.Attributes.Add("onmouseout", "if(this!=prevselitem){this.style.backgroundColor='#ffffff'}");//当鼠标移开时还原背景色
e.Row.Attributes.Add("onclick", e.Row.ClientID.ToString() + ".checked=true;selectx(this)");
}
}
aspx
<script type="text/javascript">
var prevselitem=null;
function selectx(row)
{
if(prevselitem!=null)
{
prevselitem.style.backgroundColor='#ffffff';
}
row.style.backgroundColor='PeachPuff';
prevselitem=row;
}
</script>
发布人信息
- 联系人:HeZeCheng 查看该用户发布的所有信息
- 电话:
- 邮箱:
- 地址:



