小弟初学在vs.net中用vb.net编写asp.net.
对于这个问题,我在datagrid控件的itemdatabound事件中编程如下,但达不到我想要的效果.
Private Sub dg1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dg1.ItemDataBound
 '实现鼠标移到那行以不同颜色显示
  if (e.Item.ItemType = ListItemType.Item And e.Item.ItemType = ListItemType.AlternatingItem) Then
  e.Item.Attributes.Add("onmouseover", "currentcolor = this.style.backgroundcolor;this.style.backgroundcolor ='#ff0033'")
  e.Item.Attributes.Add("onmouseout", "this.style.backgroundcolor=currentcolor")
  End If
End Sub
请各位帮忙看看!!

解决方案 »

  1.   


     就是这样写呀在if ……语句里
     e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=""" & "#FFFFFF" & """")
     e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor=""" & "#EFF3F7" & """") 这样有效果呀。
      

  2.   

    if (e.Item.ItemType = ListItemType.Item And e.Item.ItemType = ListItemType.AlternatingItem) Then
      e.Item.Attributes.Add("onmouseover", "currentcolor = this.style.backgroundcolor;this.style.backgroundcolor ='#ff0033';")
      e.Item.Attributes.Add("onmouseout", "this.style.backgroundcolor=currentcolor;")
      End If
      

  3.   

    private void grid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    if(e.Item.ItemIndex>=0) 
    {
    string title="鼠标放上时的颜色";
    string bgcolor="离开时的颜色";
    e.Item.Attributes.Add("onMouseOver","this.style.backgroundColor='"+title+"'; this.style.cursor='hand';");
    e.Item.Attributes.Add("onMouseOut","this.style.backgroundColor='"+bgcolor+"';");  
    }