参考自 http://www.cnblogs.com/hackate/archive/2005/09/07/231549.html
---------------------------------------------------------------------------------------------
DataList1_ItemDataBound
i = i + 1
If i > 3 And i <= 6 Then
e.Item.BackColor = Color.Blue
End If
If i >= 6 Then
i = 0
---------------------------------------------------------------------------------------------
if(e.Item.ItemIndex == -1)
return;
System.Web.UI.HtmlControls.HtmlTableCell tdfirst = new HtmlTableCell();
System.Web.UI.HtmlControls.HtmlTableCell tdsecond = new HtmlTableCell();
int i = e.Item.ItemIndex ;
tdfirst = (HtmlTableCell)e.Item.FindControl("firsttd");
if(tdfirst != null)
{
if(i%4 == 0) //第一行的背景色
tdfirst.BgColor = "#eaeaea";
else if(i%2 == 0) //第二行的背景色
tdfirst.BgColor = "#f3f3f3";
}
tdsecond = (HtmlTableCell)e.Item.FindControl("secondtd");
if(tdsecond != null)
{
if(i%4 == 1)//第一行的背景色
tdsecond.BgColor = "#eaeaea";
else if(i % 4 == 3)
tdsecond.BgColor = "#f3f3f3";
}
本文介绍如何在ASP.NET中使用DataList控件,并通过ItemDataBound事件为不同位置的项设置不同的背景颜色。具体实现包括对特定索引的项应用颜色样式,以增强用户界面的视觉效果。
155

被折叠的 条评论
为什么被折叠?



