或者onclick gridview中的行,使单击的这一行高亮显示

解决方案 »

  1.   

    if (!objbeforeItem)
        {
            var objbeforeItem=null;
            var objbeforeItembackgroundColor=null;
        } 
        function ItemOver(obj)
        {
            if(objbeforeItem)
            {
                objbeforeItem.style.backgroundColor = objbeforeItembackgroundColor;
            }
            objbeforeItembackgroundColor = obj.style.backgroundColor;
            objbeforeItem = obj;
            obj.style.backgroundColor = "#B9D1F3";     
        }        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType==DataControlRowType.DataRow)
                {
                    e.Row.Attributes.Add("onclick", "ItemOver(this)");
    }
    }
      

  2.   

    在RowDataBound中以 e.Row.Attributes.Add的方法给行加脚本
      

  3.   

    CheckBox的判断和颜色改变的控制。   <script>  
       function checkme(obj,tr){
       if(obj.checked)
          tr.style.backgroundColor='blue';
       else
          tr.style.backgroundColor='';
        }
        </script>  后台;
    if(!IsPostBack)
     {
    for(i=0;i<DataGrid1.Items.Count;i++){
      radio cb;
      cb=(radio)DataGrid1.Items[i].FindControl("radio"); 
      DataGrid1.Items[i].Attributes.Add("id","tr" + i.ToString()); 
      cb.Attributes.Add("onclick","checkme(this,tr" + i.ToString() + ");"); 
     }
    }