DataList的颜色问题
<asp:DataList id= "DataList1 " runat= "server " Width= "100% "> <ItemTemplate> <TABLE height= "1 " cellSpacing= "0 " cellPadding= "0 " width= "100% " border= "0 "> <TR>
<TD bgColor= "#6d7bf7 "> </TD> </TR> </TABLE>
<TABLE height= "20 " cellSpacing= "0 " cellPadding= "0 " width= "100% " bgColor= "#dbe9fb " border= "0 "> <TR>
<TD class= "lanlv12-2 " align= "center " width= "10% "> 发言人: </TD>
<TD align= "left " width= "15% ">
<asp:Label id= "Label1 " runat= "server "> </asp:Label> </TD>
<TD class= "lanlv12-2 " align= "center " width= "10% "> 发言时间: </TD>
<TD align= "left " width= "66% ">
<asp:Label id= "Label2 " runat= "server "> </asp:Label> </TD> </TR> </TABLE> <TABLE height= "80 " cellSpacing= "4 " cellPadding= "4 " width= "100% " border= "0 "> <TR> <TD vAlign= "top " align= "left ">
<asp:Label id= "Label3 " runat= "server "> </asp:Label> </TD>
</TR>
</TABLE>
</ItemTemplate>
</asp:DataList>
===========================================
我想显示的时候把
<TABLE height= "20 " cellSpacing= "0 " cellPadding= "0 " width= "100% " bgColor= "#dbe9fb " border= "0 "> <TR>
<TD class= "lanlv12-2 " align= "center " width= "10% "> 发言人: </TD>
<TD align= "left " width= "15% ">
<asp:Label id= "Label1 " runat= "server "> </asp:Label> </TD>
<TD class= "lanlv12-2 " align= "center " width= "10% "> 发言时间: </TD>
<TD align= "left " width= "66% ">
<asp:Label id= "Label2 " runat= "server "> </asp:Label> </TD> </TR> </TABLE>
的背景色换成别的 颜色交替
在事件private void DataList1_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{}
怎么写
------解决方案--------------------模板里面可以设置!不用写代码吧!!
------解决方案--------------------如果只是想颜色不同,你再写一个AlternatingItemTemplate,然后让其颜色和ItemTemplate不一样就可以了
如果是想鼠标移动的时候颜色动态交替更改,可以
private void DataList1_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
e.Item.Attributes.Add( "onmouseover ", "this.style.backgroundColor= 'seashell ' ");
if(e.Item.ItemType == ListItemType.Item)
{
e.Item.Attributes.Add( "onmouseout &