DataGrid鼠标到达的行和列显示不同的颜色

  private void listuser_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
  {
   ImageButton deleteBtn=(ImageButton)e.Item.FindControl("deleteBtn");
   if(deleteBtn!=null)
   {
    deleteBtn.Attributes.Add("onclick","return confirm('你确定要删除此用户吗?删除后此用用户将无法登录!');");
   }

   if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)  
   {
    e.Item.Attributes.Add("onmouseover","this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='#C8F7FF'");
          e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=this.oldcolor");
             for (int i=0;i<listuser.Columns.Count;i++)      
    {
     e.Item.Cells[i].Attributes.Add("onmouseover","this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='#99ccff'");
     e.Item.Cells[i].Attributes.Add("onmouseout", "this.style.backgroundColor=this.oldcolor");
    }
   }
  }


this.listuser.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.listuser_ItemDataBound);

posted on 2006-08-08 14:58  石川  阅读(103)  评论(0编辑  收藏  举报