Repeater实现颜色交替
<table cellpadding="0" cellspacing="1" border="0" width="100%" style="background-color:#efefef">
<tr>
<td class="tdCenter">讨论组</td>
<td class="tdCenter">创建时间</td>
<td class="tdCenter">是否可用</td>
<td class="tdCenter">编辑</td>
</tr>
<asp:Repeater ID="rptOrg" runat="server" OnItemCommand="rptOrg_ItemCommand" OnItemDataBound="rptOrg_ItemDataBound">
<ItemTemplate>
<tr id="trOrgInfo" runat="server">
<td class="tdRpt" align="center">
<asp:HyperLink ID="HypOrg" runat="server" Font-Size="12px"></asp:HyperLink>
</td>
<td class="tdRpt">
<asp:Label ID="lblInsertTime" runat="server" Font-Size="12px"></asp:Label>
</td>
<td class="tdRpt">
<asp:Label ID="lblIsReal" runat="server" Font-Size="12px"></asp:Label>
</td>
<td class="tdRpt">
<asp:LinkButton ID="lbtnDel" runat="server" Font-Size="12px" Text="删除"></asp:LinkButton>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
protected void rptOrg_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
string OrgID = DataBinder.Eval(e.Item.DataItem, "DisOrg_Id").ToString();
string IsReal = DataBinder.Eval(e.Item.DataItem, "DisOrg_IsReal").ToString();
((HyperLink)e.Item.FindControl("HypOrg")).Text = DataBinder.Eval(e.Item.DataItem, "DisOrg_Name").ToString();
((HyperLink)e.Item.FindControl("HypOrg")).NavigateUrl = "OnlineT_OrgEdit.aspx?Edit=Update&OrgID="
+ OrgID;
((Label)e.Item.FindControl("lblInsertTime")).Text = DataBinder.Eval(e.Item.DataItem, "DisOrg_InsertTime").ToString();
if (IsReal == "1")
{
((Label)e.Item.FindControl("lblIsReal")).Text = "可用";
}
else
{
((Label)e.Item.FindControl("lblIsReal")).Text = "不可用";
}
LinkButton lbtnDel = (LinkButton)e.Item.FindControl("lbtnDel");
<tr>
<td class="tdCenter">讨论组</td>
<td class="tdCenter">创建时间</td>
<td class="tdCenter">是否可用</td>
<td class="tdCenter">编辑</td>
</tr>
<asp:Repeater ID="rptOrg" runat="server" OnItemCommand="rptOrg_ItemCommand" OnItemDataBound="rptOrg_ItemDataBound">
<ItemTemplate>
<tr id="trOrgInfo" runat="server">
<td class="tdRpt" align="center">
<asp:HyperLink ID="HypOrg" runat="server" Font-Size="12px"></asp:HyperLink>
</td>
<td class="tdRpt">
<asp:Label ID="lblInsertTime" runat="server" Font-Size="12px"></asp:Label>
</td>
<td class="tdRpt">
<asp:Label ID="lblIsReal" runat="server" Font-Size="12px"></asp:Label>
</td>
<td class="tdRpt">
<asp:LinkButton ID="lbtnDel" runat="server" Font-Size="12px" Text="删除"></asp:LinkButton>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
protected void rptOrg_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
string OrgID = DataBinder.Eval(e.Item.DataItem, "DisOrg_Id").ToString();
string IsReal = DataBinder.Eval(e.Item.DataItem, "DisOrg_IsReal").ToString();
((HyperLink)e.Item.FindControl("HypOrg")).Text = DataBinder.Eval(e.Item.DataItem, "DisOrg_Name").ToString();
((HyperLink)e.Item.FindControl("HypOrg")).NavigateUrl = "OnlineT_OrgEdit.aspx?Edit=Update&OrgID="
+ OrgID;
((Label)e.Item.FindControl("lblInsertTime")).Text = DataBinder.Eval(e.Item.DataItem, "DisOrg_InsertTime").ToString();
if (IsReal == "1")
{
((Label)e.Item.FindControl("lblIsReal")).Text = "可用";
}
else
{
((Label)e.Item.FindControl("lblIsReal")).Text = "不可用";
}
LinkButton lbtnDel = (LinkButton)e.Item.FindControl("lbtnDel");
lbtnDel.OnClientClick = "javascript:return confirm('您确定要删除该项么?')";
lbtnDel.CommandName = "Delete";
lbtnDel.CommandArgument = OrgID;
int i = e.Item.ItemIndex % 2;
if (i == 0)
{
((HtmlTableRow)e.Item.FindControl("trOrgInfo")).BgColor = "#ffffff";
}
else
{
((HtmlTableRow)e.Item.FindControl("trOrgInfo")).BgColor = "#f9f9f9";
}
}
}