Editing static text in ItemTemplate

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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.
 
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
 
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
 
I apologize for being curt. No place for that. I should have explained
better.

Greg
 
Back
Top