您的位置:首页 > 其它

GridView显示数据鼠标悬停变色

2014-07-04 20:31 417 查看

 一、 首先在前台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");      //鼠标移走颜色还原

            }

        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: