0

我想在 jquery 中绑定我的数据列表。这是我的客户端代码:

<head>
     <script src="jss/jquery.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {

            $.ajax({
                type: "POST",
                url: "WebForm1.aspx/GetProducts",
                data: '{}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: OnSuccess,
                failure: function (response) {
                    alert(response.d);
                },
                error: function (response) {
                    alert(response.d);
                }
            });
        });

        function OnSuccess(response) {
            $("[id*=dlOnFrontPageProducts]").attr("border", "1");
            var xmlDoc = $.parseXML(response.d);
            var xml = $(xmlDoc);
            var customers = xml.find("Table1");
            var row = $("[id*=dlOnFrontPageProducts] tr:last-child").clone(true);
            $("[id*=dlOnFrontPageProducts] tr:last-child").remove();
            $.each(customers, function () {
                alert(this);
                var customer = $(this);
                $(".Name", row).html(customer.find("Name").text());
                $(".BrandName", row).html(customer.find("BrandName").text());
                $(".MarketPrice", row).html(customer.find("MarketPrice").text());
                $(".CurrencyShortName", row).html(customer.find("CurrencyShortName").text());
                $(".Price", row).html(customer.find("Price").text());
                $(".WindowImageUrl", row).html(customer.find("WindowImageUrl").text());
                $(".SaleCount", row).html(customer.find("SaleCount").text());
                $(".IsActive", row).html(customer.find("IsActive").text());
                $("[id*=dlOnFrontPageProducts]").append(row);
                row = $("[id*=dlOnFrontPageProducts] tr:last-child").clone(true);
            });
        }

    </script>

</head>
<body>
    <asp:DataList runat="server" ID="dlOnFrontPageProducts" RepeatColumns="4" RepeatDirection="Horizontal"
        RepeatLayout="Table" EnableTheming="True" OnItemDataBound="dlChanceProducts_ItemDataBound">
        <ItemTemplate>
            <div class="box-product fixed">
                <div class="prod_hold">
                    <a class="wrap_link" href="ProductDetail.aspx?prid=<%# Eval("ProductId") %>"><span
                        class="images">
                        <asp:Image runat="server" ID="imgWindow" /></span> </a>
                    <div class="pricetag_small">
                        <span class="old_price">
                            <%# Eval("MarketPrice")%><%# Eval("CurrencyShortName")%></span> <span class="new_price">
                                <%# Eval("Price", "{0:n}")%>
                                <%# Eval("CurrencyShortName")%></span>
                    </div>
                    <div class="info">
                        <h3>
                            <%# Eval("Name") %></h3>
                        <p>
                            <%# Eval("BrandName")%></p>
                        <a class="add_to_cart_small" href="/core/ajaxresult.aspx?act=prod&prid=<%#Eval("ProductId")%>">
                            Sepete Ekle</a> <a class="wishlist_small" href="#">Listeme Ekle</a> <a class="compare_small"
                                href="#">Karşılaştır</a>
                    </div>
                </div>
            </div>
            <div class="clear">
            </div>
        </ItemTemplate>
    </asp:DataList>
</body>

我返回的数据是正确的,但 datalist 没有绑定。你有什么建议吗?

4

1 回答 1

0

这是我的代码,请检查您的代码并进行适当的更改并获得答案

ASP.NET 代码:

<asp:DataList ID="dlCustomers" runat="server" RepeatLayout="Table" RepeatColumns="3"
                            CellPadding="3" CellSpacing="3" HeaderStyle-VerticalAlign="Top">
                            <ItemStyle HorizontalAlign="Center" />
                            <ItemTemplate>
                                <table cellpadding="3" cellspacing="3" border="1" style="width: 310px; height: 100px; border: thin 2px #428bca; color: black; background-color: #EEEEEE">
                                    <tr>
                                        <td style="text-align: center; background-color: cyan; color: black">
                                            <b><span class="plot"><%# Eval("PlotNumber") %> </span></b>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Seasoncode:<span class="Season"><%# Eval("Seasoncode") %> </span>
                                            <br />
                                            Village: <span class="Village"><%# Eval("Village") %></span><br />
                                            Planting Date: <span class="PlantingDate"><%# Eval("PlantingDate")%></span><br />
                                            Plant: <span class="Planttype"><%# Eval("Planttype")%></span> &nbsp;&nbsp;
                                            Crop: <span class="CropType"><%# Eval("CropType")%></span> &nbsp;&nbsp;
                                            Nursery: <span class="NurseryType"><%# Eval("NurseryType")%></span><br />
                                            Cutas Setts: <span class="CutasSetts"><%# Eval("CutasSetts")%></span><br />
                                            Seed Supply: <span class="SeedSupply"><%# Eval("SeedSupply")%></span><br />
                                            Cutas Bulk: <span class="CutasBulk"><%# Eval("CutasBulk")%></span><br />
                                            Cane Supply: <span class="CaneSupply"><%# Eval("CaneSupply")%></span><br />
                                        </td>
                                    </tr>
                                </table>
                            </ItemTemplate>
                        </asp:DataList>

jQuery代码: -


function plot_details(paramstr) {
            $("[id*=dlCustomers]").hide();

            $.ajax({
                type: "POST",
                url: "CommonView.aspx/GetCustomers",
                data: "{'paramstr': '" + paramstr + "', 'procname': '" + 'DBSP_Get_PartyPlotView' + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: OnSuccess,
                failure: function (response) {
                    alert(response.d);
                },
                error: function (response) {
                    alert(response.d);
                }
            });
        }

        function OnSuccess(response) {
            var xmlDoc = $.parseXML(response.d);
            var xml = $(xmlDoc);
            var customers = xml.find("Table");
            var repeatColumns = parseInt("<%=dlCustomers.RepeatColumns == 0 ? 1 : dlCustomers.RepeatColumns %>");
            var rowCount = Math.ceil(customers.length / repeatColumns);
            var i = 0;

            while (i < repeatColumns * rowCount) {
                var row = $("[id*=dlCustomers] tr").eq(0).clone(true);
                for (var j = 0; j < repeatColumns; j++) {
                    var customer = $(customers[i]);
                    if (customer.length == 0) {
                        $("table:last", row).remove();
                    } else {
                        $(".plot", row).eq(j).html(customer.find("PlotNumber").text());
                        $(".Season", row).eq(j).html(customer.find("Seasoncode").text());
                        $(".Village", row).eq(j).html(customer.find("Village").text());
                        $(".PlantingDate", row).eq(j).html(customer.find("PlantingDate").text());
                        $(".Planttype", row).eq(j).html(customer.find("Planttype").text());
                        $(".CropType", row).eq(j).html(customer.find("CropType").text());

                        $(".NurseryType", row).eq(j).html(customer.find("NurseryType").text());
                        $(".Variety", row).eq(j).html(customer.find("Variety").text());
                        $(".CutasSetts", row).eq(j).html(customer.find("CutasSetts").text());
                        $(".CutasBulk", row).eq(j).html(customer.find("CutasBulk").text());
                        $(".SeedSupply", row).eq(j).html(customer.find("SeedSupply").text());
                        $(".CaneSupply", row).eq(j).html(customer.find("CaneSupply").text());
                    }
                    i++;
                }
                $("[id*=dlCustomers]").append(row);
            }
            $("[id*=dlCustomers] tr").eq(0).remove();
            $("[id*=dlCustomers]").show();
        }
于 2017-02-10T12:42:49.107 回答