datagrid在net应用十分广泛,但是在很多场合都需要特殊的显示效果以强调或突出某些内容,使用户在查看数据时更加方便明了.

     1:设置datagrid的行交替显示颜色效果,只有现在datagrid属性中设BackColor="Linen"和 AlternatingItemStyle BackColor="Lavender"即可.我这里使用了"Lavender"和"Linen",只有这两个颜色不同,就会出现行与行的不同颜色.

     2:使用marquee将datagrid的内容放到滚动区域滚动<*.aspx的html中>
     <marquee
    scrollAmount="1" scrollDelay="30" direction="up" width="780" bgColor="#ffccff" height="500">
    <table >
     <tr width="780">
      <td><asp:datagrid
        BackColor="Linen" OnItemDataBound="DataGrid1_ItemDataBound">
        <AlternatingItemStyle BackColor="Lavender"></AlternatingItemStyle>
        <HeaderStyle HorizontalAlign="Center" ForeColor="#FF0099" BackColor="#FFCCFF"></HeaderStyle>
       </asp:datagrid></td>
     </tr>
    </table>
    </TABLE></marquee>

   3:  实现鼠标在datagrid上移动到不同行产生不同颜色,移动过后恢复原来的颜色 在代码(*.vb中)  
     

Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)

 

        '------------------------------------------------------------------

        ' Add the OnMouseOver and OnMouseOut method to the Row of DataGrid

        '------------------------------------------------------------------

 

        If (e.Item.ItemType = ListItemType.Item) Then

 


            e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='red'")

 

            e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='linen'")

        End If

        If (e.Item.ItemType = ListItemType.AlternatingItem) Then

            e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='yellow'")

 

            e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='lavender'")

        End If

 

    End Sub





相关文章:

  • 2022-12-23
  • 2021-06-27
  • 2022-12-23
  • 2021-08-24
  • 2021-10-14
  • 2021-07-27
  • 2022-12-23
猜你喜欢
  • 2021-09-22
  • 2022-12-23
  • 2021-10-21
相关资源
相似解决方案