• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

大佬罗的博客

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

datagrid特效(交替颜色)


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

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

     2:使用marquee将datagrid的内容放到滚动区域滚动<*.aspx的html中>
     <marquee id="scrollArea" onmouseover="scrollArea.stop()" onmouseout="scrollArea.start()"
    scrollAmount="1" scrollDelay="30" direction="up" width="780" bgColor="#ffccff" height="500">
    <table id="aaa" width="780" border="1">
     <tr width="780">
      <td><asp:datagrid id="DataGrid1" runat="server" Height="494px" Width="772px" Font-Size="Smaller" HorizontalAlign="Center"
        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





posted on 2005-03-22 09:20  Richinger  阅读(1998)  评论(12)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3