在GridView 中,经常会需要一种这样的效果,当鼠标放在某一行时,某一行有一个CSS效果,当鼠标移开该行时,又有另外一个效果,这其实就是利用了onmouseover的效果,实现起来其实很简单,在GridView的
Row_DataBound事件中这样实现就可以了
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "lastColor=this.style.backgroundColor;this.style.backgroundColor='#dddddd';");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=lastColor;");
}
}
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "lastColor=this.style.backgroundColor;this.style.backgroundColor='#dddddd';");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=lastColor;");
}
}
                    
                
                
            
        
浙公网安备 33010602011771号