By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,052 Members | 1,303 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,052 IT Pros & Developers. It's quick & easy.

Add new row to Repeater?

P: n/a
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!

Sep 23 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

Steve wrote:
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!
Sep 23 '06 #2

P: n/a
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

Steve wrote:
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!
Sep 23 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.