或有其他替代方法?

解决方案 »

  1.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#C1D2EE'");
                    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white'");            }
      

  2.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex > -1)
            {
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor = 'lightyellow';");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor = 'white';");
            }
        }
      

  3.   

    //以下方法实现当鼠标移动到该行时颜色改变,移出后变回原色
    在datagrid的属性中选择事件,双击ItemDataBound事件,在.cs中:
    private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if(e.Item.ItemType == ListItemType.Item||e.Item.ItemType == ListItemType.AlternatingItem)
    {
    e.Item.Attributes.Add("onmouseover","c=this.style.backgroundColor;this.style.backgroundColor = '#ddeeff'");
    e.Item.Attributes.Add("onmouseout","this.style.backgroundColor = c;");
    }
      

  4.   

    protected void GridViewSys_RowDataBound(object sender, GridViewRowEventArgs e)
        {
             //加入鼠标滑过的高亮效果
            if (e.Row.RowType == DataControlRowType.DataRow)//判定当前的行是否属于datarow类型的行
            {
                //当鼠标放上去的时候  
                e.Row.Attributes["OnMouseOver"]="TableRow_OnMouseOver(this)";
                e.Row.Attributes["OnMouseOut"] ="TableRow_OnMouseOut(this)";
            }    }