GridView选中变色不刷新

来源:互联网 发布:新浪微博数据库设计 编辑:程序博客网 时间:2024/06/05 18:30
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"  

                       DataKeyNames="id"  GridLines="None"   onRowDatabound="GridView1_RowDataBound">

注意选中

 后台
 protected void gvWorkFlow_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //判断是否是数据行
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "if(this!=prevselitem){c=this.style.backgroundColor;this.style.backgroundColor='#999999'}");//当鼠标停留时更改背景色
            e.Row.Attributes.Add("onmouseout", "if(this!=prevselitem){this.style.backgroundColor=c}");//当鼠标移开时还原背景色
            e.Row.Attributes.Add("onclick", e.Row.ClientID.ToString() + ".checked=true;selectx(this)");
        }
    }
前台 JS
<script language="javascript" type="text/javascript">
      var prevselitem=null;
      function selectx(row)
      {
              if(prevselitem!=null)
              {
                  prevselitem.style.backgroundColor='#ffffff';
              }
              row.style.backgroundColor='PeachPuff';
              prevselitem=row;
              
      }     
</script>

0 0