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 阅读(1973) 评论(12) 编辑 收藏 举报