Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to bind repeater with cities ('Mathura','Agra','Allahabad')


C#
protected void Page_Load(object sender, EventArgs e)
    {
        
        try
        {
            if (!IsPostBack)
            {

                DataTable dummy = new DataTable();
                dummy.Columns.Add("City");
                               dummy.Rows.Add();
              
              rptFPS.DataSource = dummy;
              rptFPS.DataBind();

            }
        }
        catch (Exception ex)
        {

        }


    }

ASP.NET
<table id="rptCustomers">
 <tr><th>City</th></tr>
<asp:Repeater ID="rptFPS" runat="server">                                                <ItemTemplate>
<tr>
<td>
<asp:Label  Text='<%# Eval("City") %>' runat="server" />                                         </td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>

JavaScript
function BindRepeater() {
            try {
      
      var row = $("[id*=rptCustomers] tr:last-child").clone(true);
      $("[id*=rptCustomers] tr:last-child").remove();                      
      $(".City", row).html("Agra");
      $("[id*=rptCustomers]").append(row);                

            }
            catch (e) {

            }
        }
Posted
Updated 31-Jan-16 22:38pm
v5
Comments
F-ES Sitecore 1-Feb-16 4:25am    
The repeater only exists on the server, you can't interact with it using js on the client. Ignore the whole repeater idea and google how to create a table via jQuery and json and you'll find examples.
Member 7909353 1-Feb-16 4:37am    
Actually! I have nested repeater and a gridview inside last repeater.
like repeate1(state) ,repeater2(city) and gridview(village) has information

1 solution

 
Share this answer
 
Comments
Member 7909353 1-Feb-16 1:57am    
I have only commo seperated string like 'Mathura','Agara','Allahabad'.
not table for xml.
DamithSL 1-Feb-16 2:04am    
understand the concept, that sample code adding dummy item to repeater and clone it first and remove that row from jquery. cloned item updated with new value and add to repeater for all the records.
Member 7909353 1-Feb-16 2:17am    
In my code
I clone the row first and remove that row from jquery. cloned item updated with new value and add to repeater for all the records.
DamithSL 1-Feb-16 2:24am    
repeater will not have first row if you haven't bind data. jquery runs on client side , ASP.NET repeater server control generate from server side. you can't clone or find first row in this case. it will fail in the beginning

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900