五、初学.NET—Gridview自动编号和鼠标停留行加背景

前端:在GridView中添加一普通绑定列

<asp:BoundField  HeaderText="序号" ItemStyle-Width="60px">

<ItemStyle Width="60px"></ItemStyle>

        </asp:BoundField>

后台:通过RowDataBound事件处理代码后台绑定,鼠标停留一行加背景

protected void gv_ReviewOption_RowDataBound(object sender, GridViewRowEventArgs e)

    {

        if (e.Row.RowType == DataControlRowType.DataRow)

        {  int id = e.Row.RowIndex + 1;

           e.Row.Cells[1].Text = id.ToString();

           e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='lightblue'");//鼠标移上去时

           e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor;");//鼠标移开时

        }

    }

原文地址:https://www.cnblogs.com/liuyuanhao/p/3012950.html