GridView显示数据鼠标悬停变色

 一、 首先在前台GridView中加上onrowdatabound="GridView1_RowDataBound":

  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                        onrowdatabound="GridView1_RowDataBound">

   .......

 </asp:GridView>

二、然后在后台的GridView1_RowDataBound事件中写

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {


                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#99FFCC'");     //鼠标悬停变色
              
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");      //鼠标移走颜色还原
            }
        }

你可能感兴趣的:(GridView)