Reputation: 664
Good afternoon.
I have a Repeater with a ItemTemplate that prints one column with data.
<asp:Repeater id="OtherProductsRepeater" runat="server">
<ItemTemplate>
(...data...)
</ItemTemplate>
</asp:Repeater>
How can i modify the code to instead of one column create three columns to show the data?
Thanks in advance.
Upvotes: 1
Views: 3876
Reputation: 21905
Edited to show using repeater to make a three column layout
<table>
<asp:Repeater id="OtherProductsRepeater" OnItemCreated="OtherProductsRepeater_ItemCreated" runat="server">
<ItemTemplate>
<asp:PlaceHolder id="row_end" visible="<%# _showRowEnd %>" runat="server">
</tr>
</asp:PlaceHolder>
<asp:PlaceHolder id="row_start" visible="<%# _showRowStart %>" runat="server">
<tr>
</asp:PlaceHolder>
<td>(data)</td>
<td>(data)</td>
<td>(data)</td>
</ItemTemplate>
</asp:Repeater>
</tr> <%-- close final row --%>
</table>
in your code, you need these page level members:
private int _rowCounter = 0;
protected bool _showRowEnd;
protected bool _showRowStart;
and the event handler:
protected void OtherProductsRepeater_ItemCreated(Object Sender, RepeaterItemEventArgs e) {
if (_rowCounter == 0) { // first row
_showRowStart = true;
_showRowEnd = false;
_rowCounter = 1;
}
else if (_rowCounter == 3) {
_showRowStart = true;
_showRowEnd = true;
_rowCounter = 1;
}
else {
_showRowStart = false;
_showRowEnd = false;
_rowCounter += 1;
}
}
Another thought - if you are talking about newspaper-style columns, where the content flows from the bottom of one column to the top of the next, use a DataList control instead of a repeater.
Upvotes: 5
Reputation: 11858
If you're using ASP.net 3.5 or higher you should use ListView and the GroupTemplate.
For example code, See...
https://web.archive.org/web/20211020150712/https://www.4guysfromrolla.com/articles/010208-1.aspx
Upvotes: 0
Reputation: 18215
be sure to encapsulate all the mark up in the single control in case visible=false
, or item.count=0
<asp:Repeater id="OtherProductsRepeater" runat="server">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>(data)</td>
<td>(data)</td>
<td>(data)</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
Upvotes: 1