Scorpio
Scorpio

Reputation: 1171

Binding Serialized JSON data to repeater

 protected void BindData()
    {
        List<Product> products = product.GetRepeaterData(prod);
        string json = JsonConvert.SerializeObject(products);
        dataRepeater.DataSource = json;
        dataRepeater.DataBind();
    }

 <asp:Repeater ID="dataRepeater" runat="server">
    <HeaderTemplate>
        List<div id="accordion">
    </HeaderTemplate>
    <ItemTemplate>
        <h3>
            <a href="#" style="background-color: gray; height: 25px; color: White; text-decoration: none;">
                <%# DataBinder.Eval(Container.DataItem, "Name")%></a></h3>
        <div>
            <ul>
                <li><span>Id:
                    <%# DataBinder.Eval(Container.DataItem, "Id")%></span></li>
                <li><span>OrganizationId:
                    <%# DataBinder.Eval(Container.DataItem, "Organization")%></span>    </li>
                <li><span>ParentProduct:
                    <%# DataBinder.Eval(Container.DataItem, "Product")%></span></li>
        </div>
    </ItemTemplate>
    <FooterTemplate>
        </div></FooterTemplate>
</asp:Repeater>

error: DataBinding: 'System.Char' does not contain a property with the name 'Name'. 
 <%# DataBinder.Eval(Container.DataItem, "Name")%></a></h3>

I am a new to the whole concept of JSON and Ajax. We are getting lot of data from a webservice so its slowing down the process till the call is complete. I have to make this an async call using JSON and Ajax. Currently I am able to serialize/deserialize the data before binding now I dont see any point in binding the data after deserializing it to the repeater so I am trying to bind the serialized data to the repeater but its not binding. Secondly can anyone please tell me how to do this as an ajax call? Will adding update panel on the client side suffice the purpose ? I am sorry I know this question is a bit vague but I am lost right now..any documentation or examples will also help.. as I am not sure that this is the right way of doing it....

Upvotes: 0

Views: 5218

Answers (1)

Chad Ruppert
Chad Ruppert

Reputation: 3680

JSON is intended to be used clientside, and you would NOT use server side controls to do the binding.

If you want binding syntax, there are many frameworks out there for that. knockout, mustache, etc.

Typically though, you get the JSON through an ajax call, and use that data to add markup to the DOM in the way that you need. Forget Server side controls unless you want to use an updatepanel or similar.

Upvotes: 1

Related Questions