设置DataGrid的SelectStyle属性就可以实现啦,很简单

解决方案 »

  1.   

    有两种方法:
    1.如  matu(宝贝)所说 设置DataGrid的SelectStyle属性就可以实现
    2.
     Private Sub dgMessage_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgMessage.ItemDataBound
            If e.Item.ItemIndex <> -1 Then
                '添加自定义属性,当鼠标移过来时设置该行的背景色为"d4e8ff",并保存原背景色
                e.Item.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#d4e8ff' ;this.style.cursor='hand'")
                '添加自定义属性,当鼠标移走时还原该行的背景色
                e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor ;this.style.cursor='hand'")
                '当鼠标点击时背景色改变
                e.Item.Attributes.Add("onmousedown", "this.style.backgroundColor='f18d34'")
            End If
        End Sub
      

  2.   

    if((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType==ListItemType.AlternatingItem   ))
    {
      LinkButton lbDelete=new LinkButton();
      lbDelete=e.Item.FindControl("btnDelete") as LinkButton ;
      lbDelete.Attributes.Add("onclick","javascript:return confirm('真的要删除记录吗?')");
                  
      e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#ffced1';this.style.cursor='crosshair'");
      //e.Item.Attributes.Add("onclick", "this.style.backgroundColor='#FFC0C0';this.style.cursor='crosshair'");
      if (e.Item.ItemType==ListItemType.AlternatingItem   )
          e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#F1EEFF'");
                  if (e.Item.ItemType == ListItemType.Item) 
      e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#DFDEE7'"); }
      

  3.   

    看看这个www.foxhis.com/powermjtest/可以实现你说的功能,免费,开源!
      

  4.   

    nk912114(ktf)所说的第一种方法必须添加一个超级链接列才可实现,但我并不想加上这一列,第二种方法当选择完一行后,再选另外一行时,先前行的背景色会改变成初始状态吗?我觉得好像不行哦,lyhold(让你飞) 所说的也是一回事情!
      

  5.   

    cuike519(Knowledge is Power)你所说的www.foxhis.com/powermjtest/这个是一个不错的东东,但目前只提供dll,源代码估计需要等一段时间,并且目前还不是很稳定,希望作者能尽快提供源代码,有什么问题大家可以一起研究,我建议他放到http://sourceforge.net/上面去!!
      

  6.   

    to: DanielQQ() 
    呵呵,那个就是cuike519(Knowledge is Power)大哥自己的作品呢。
      

  7.   

    to: DanielQQ()   我的第二种方法是可以实现你所要的效果的!
       我在我的程序种实现了,你可以试一下.
       ^_^
      

  8.   

    to: nk912114(ktf)
    但是你的方法点击过后当鼠标移走后就没有背景色了啊?你发现了吗?
      

  9.   

    to: nk912114(ktf)
    我也试过了,问题同wggwan(明天会更好) 一样,^_^!
    难道说只能通过第三方控件才可实现吗?
      

  10.   

    http://expert.csdn.net/Expert/topic/2982/2982827.xml?temp=.9309503