I want to put <br>
tag only in front of 6th item.
how can I do this?
<asp:Repeater ID="rptWinner" runat="server">
<HeaderTemplate></HeaderTemplate>
<ItemTemplate&g开发者_如何学运维t;
<%# GetWinnerID(Container.DataItem) %>
</ItemTemplate>
<FooterTemplate></FooterTemplate>
</asp:Repeater>
Try this:
<asp:Repeater ID="rptWinner" runat="server">
<HeaderTemplate></HeaderTemplate>
<ItemTemplate>
<%# GetWinnerID(Container.DataItem) %>
<%# Container.ItemIndex == 4 ? "<br />" : string.Empty %>
</ItemTemplate>
<FooterTemplate></FooterTemplate>
</asp:Repeater>
this adds <br />
tag after the fifth element (in front of 6th).
First you'll need to add a placeholder to hold the BR, or add a label. Then you'll need to tie into the OnItemDataBound
event and do checking:
protected void rptWinner_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.Index == 6)
{
PlaceHolder ph = e.Item.FindControl("myPlaceholder") as PlaceHolder;
ph.Controls.Add(new LiteralControl("<br>"));
}
}
Or something to that effect ;)
精彩评论