0
 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>

我是 JSON 和 Ajax 整个概念的新手。我们从 Web 服务中获取大量数据,因此它会减慢进程直到调用完成。我必须使用 JSON 和 Ajax 进行异步调用。目前我能够在绑定之前对数据进行序列化/反序列化,现在我在将数据反序列化到转发器后看不到任何绑定数据的点,所以我试图将序列化数据绑定到转发器,但它没有绑定。其次,任何人都可以告诉我如何将其作为 ajax 调用来执行吗?在客户端添加更新面板是否足以达到目的?很抱歉,我知道这个问题有点含糊,但我现在迷路了..任何文档或示例也会有所帮助..因为我不确定这是正确的做法....

4

1 回答 1

1

JSON 旨在用于客户端,您不会使用服务器端控件进行绑定。

如果你想要绑定语法,有很多框架可以做到这一点。淘汰赛,小胡子等

通常,您通过 ajax 调用获取 JSON,并使用该数据以您需要的方式将标记添加到 DOM。除非您想使用更新面板或类似工具,否则请忘记服务器端控件。

于 2012-10-17T15:41:36.513 回答