ASP.NET repeater result to textbox

127 views Asked by At

I am new to asp.net.
I use a repeater in my code and i want to use the result of the repeater as text to a single textbox. The repeater code is the following:

<asp:Repeater ID="rptMarkers" runat="server">
                        <ItemTemplate>
                            [
                            <%# Eval("lat")%>,
                            <%# Eval("long") %>,
                            '<%# Eval("city")%>'
                            ]
                        </ItemTemplate>
                        <SeparatorTemplate>
                           ,
                        </SeparatorTemplate>
</asp:Repeater>

The result of the repeater is something like this:

[ 38,1413580155577, 23,761239052, 'Athens' ] , [ 38,1199989318848, 23,742678165, 'Athens' ]

and I want this row result to be written in a single textbox.text. Is that possible?

2

There are 2 answers

0
Dzoukr On

What about do it in code-behind without repeater? I assume that your markers can be iterated, so you can do something like this (using LINQ):

MyTextBox.Text = String.Join(",", MarkersCollection.Select(x => String.Format("[{0}, {1}, {2}]", x.Lat, x.Long, x.City)).ToArray());
1
JBB On

You could do it like this

<asp:Repeater ID="rptMarkers" runat="server">
      <ItemTemplate>
           <asp:TextBox runat="server" Text='<%# "[" +Eval("lat")  + " , " + Eval("long")%>  + " , " + Eval("city") + "]"' ></asp:TextBox>
       </ItemTemplate>
       <SeparatorTemplate>
        ,
       </SeparatorTemplate>
</asp:Repeater>