我在asp.net中用VB写的如下:'Private Sub dgrdRecord_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgrdRecord.ItemDataBound
    '    Dim c As Object
    '    If e.Item.ItemType = ListItemType.Item Then
    '        e.Item.Attributes.Add("onmouseover", "dgrdrecord.ItemStyle.BackColor=blue ")
    '        e.Item.Attributes.Add("onmouseout", " dgrdrecord.ItemStyle.BackColor =''")
    '    End If
    'End Sub但执行的时候,不知道为什么没反应,我觉得是ADD中第二个参数模式有问题,想请教更改一下?谢谢!

解决方案 »

  1.   

    private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
     7{
     8    if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
     9    {
    10        e.Item.Attributes.Add("onmouseover","this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='#C8F7FF'");
    11        e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=this.oldcolor");
    12        for (int i=0;i<DataGrid1.Columns.Count;i++)
    13        {
    14            e.Item.Cells[i].Attributes.Add("onmouseover","this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='#99ccff'");
    15            e.Item.Cells[i].Attributes.Add("onmouseout", "this.style.backgroundColor=this.oldcolor");
    16        }
    17    }
    18}
      

  2.   

    http://bear-study-hard.cnblogs.com/archive/2005/12/23/303131.html
      

  3.   

    '当鼠标移到的时候设置该行颜色为"", 并保存原来的背景颜色
    e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#C0C0FF'")
    '当鼠标移走时还原该行的背景色
    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor")
      

  4.   

    dgrdrecord.ItemStyle客户端还认识这个东东吗?
      

  5.   

    用this.style.backgroundColor
    不要用dgrdrecord.ItemStyle.BackColor
    ^o^
      

  6.   

    用VB的
    认得,那个就是datagrid控件
      

  7.   

    jeffamy写的那个可行
    但前面e对象没有row属性还是用的item。谢谢了!怎么结贴呢?
      

  8.   

    用js,onmouseuot,onmouse事件,好象是这个,我实现了.你再去看看.
      

  9.   

    public void ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if(e.Item.ItemType==ListItemType.AlternatingItem |e.Item.ItemType==ListItemType.Item)
    {
    e.Item.Attributes.Add("onmouseover","currentcolor=this.style.backgroundColor;this.style.backgroundColor='#ffff66'");
    //添加自定义属性,当鼠标移走时还原该行的背景色
    e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=currentcolor");
    }
    }
      

  10.   

    protected override void OnItemCreated( DataGridItemEventArgs e )
    {
    if ( e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem )
    {
    //添加鼠标移过行时背景变色效果
    e.Item.Attributes[ "onmouseover" ] = "rowColor = this.style.backgroundColor;this.style.backgroundColor = '#FFFF99'" ;
    e.Item.Attributes[ "onmouseout" ] = "this.style.backgroundColor = rowColor" ;
    }
    base.OnItemCreated( e ) ;
    }