Add new row to Repeater?

S

Steve

I am having issues adding a new row in my repeater when my repeater's
table cells reach a certain number. what i'm doing is adding a
predetermined number of color cells from the database and bringing them
into a repeater that is located already inside a table cell which
cannot exceed a certain width.

for example:

ASP:
------------------------------------
<asp:Repeater ID="Repeater1" runat="server"
OnItemDataBound="Repeater1_ItemDataBound">

<HeaderTemplate>
<table id="uiColorTable"><tr>
</HeaderTemplate>

<ItemTemplate>
<td>
<asp:panel ID="uiColorSwatch" runat="server" Height="10px"
HorizontalAlign="Center" Width="50px" BackColor='<%#
DataBinder.Eval(Container.DataItem , "ArgbColor") %>'></asp:panel>
<asp:Label ID="uiColorName" CssClass="uiColorName" runat="server"
Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>'></asp:Label>
</td>
</ItemTemplate>

<SeparatorTemplate>
<td>&nbsp;&nbsp;</td>
</SeparatorTemplate>

<FooterTemplate>
</tr></table>
</FooterTemplate>

</asp:Repeater>

C#:
--------------------------------
protected void Repeater1_ItemDataBound(object sender,
RepeaterItemEventArgs e)
{
int x = 0;
foreach (RepeaterItem tmpItem in Repeater1.Items)
{
if (x == 8)
{
LiteralControl tmpLiteral = new
LiteralControl("</td></tr><tr><td>");
Repeater1.Controls.Add(tmpLiteral);
x = 0;
}
else
{
x++;
}
}
}

to be honest, i have a feeling i'm not doing something retardedly
simple but after staring at this for a few hours, i'm starting to get
crosseyed. some help would be awesome!
 
S

Sean Chambers

Maybe you can clarify, because I don't quite see where the problem is.

If you want to display a specific number of columns, I would use a
datalist control like so:

<asp:DataList ID="DataList" Width="100%" runat="server"
ItemStyle-HorizontalAlign="Center" RepeatColumns="5"
RepeatDirection="Horizontal">

It's much easier than outputting the html yourself. I try to let
asp.net generate as much html as possible, because otherwise you have
to keep track of td and tr, and it can get cumbersome.

Is there a specific reason your using a repeater control?

hope that helps!

Sean
 
S

Sean Chambers

If you want to display a specific number of columns, I would use a
datalist control like so:

<asp:DataList ID="DataList" Width="100%" runat="server"
ItemStyle-HorizontalAlign="Center" RepeatColumns="5"
RepeatDirection="Horizontal">

It's much easier than outputting the html yourself. I try to let
asp.net generate as much html as possible, because otherwise you have
to keep track of td and tr, and it can get cumbersome.

Is there a specific reason your using a repeater control?

hope that helps!

Sean
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top