Editing static text in ItemTemplate

G

Guest

Hello,

I have a repeater control I am using to display items that are comma
separated. The code looks like this:

<asp:Repeater id="rptSummary" runat="server">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem,
Container.DataItem.Row.Table.Columns(0).ColumnName)%>,
</ItemTemplate>
</asp:Repeater>

The code works exactly as it should. However, for the last item, I would
like to remove the comma at the end of it, since obviously there is no
additional items. This is where I'm getting stuck...

How can I reference my ItemTemplate from code to remove the trailing comma?

It has been suggested to use a SeparatorTemplate to do this, but I still do
not see how to reference the final SeparatorTemplateItem after it is bound to
the data.

Thanks for the help anyone can provide.

- Andre
 
L

Lucas Tam

How can I reference my ItemTemplate from code to remove the trailing
comma?

An easier way is to place a label in the ItemTemplate. Then on the
OnItemDatabound event, dynamically set the text in the label. I think that
should work better.
 
G

Greg Burns

It has been suggested to use a SeparatorTemplate to do this, but I still
do
not see how to reference the final SeparatorTemplateItem after it is bound
to
the data.

Did you bother to even try?

<asp:Repeater id="rptSummary" runat="server">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem,
Container.DataItem.Row.Table.Columns(0).ColumnName)%>
</ItemTemplate>
<SeparatorTemplate>,</SeparatorTemplate>
</asp:Repeater>

SELECT TOP 10 CustomerID FROM customers

outputs...

ALFKI , ANATR , ANTON , AROUT , BERGS , BLAUS , BLONP , BOLID , BONAP ,
BOTTM

Greg
 
G

Guest

Hello Greg,

My apologies...

I did in fact try the SeparatorTemplate, but I immediately went to debug
mode to try and extract the final separator. I did not realize the separator
itself would not render for the last item.

This works great. Thanks for the help!

- Andre
 
G

Greg Burns

I apologize for being curt. No place for that. I should have explained
better.

Greg
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top