0

我在页面滚动上使用负载。从这个链接 http://aspsnippets.com/Articles/Load-data-while-Scrolling-Page-down-with-jQuery-AJAX-and-ASPNet.aspx

在页面加载时,它以表格的形式显示 10 条记录,我将唯一 ID 绑定到数据库中的表格。正确启动 10 行的绑定 ID,但在第 10 行之后我看到 {source code},第 10 之后所有表上的 ID 相同,它在第一个表上采用 id。删除完成后,我正在使用此表唯一 ID 来删除表。我也在这个表中使用了一个用户控件。用户控件的行为方式与表相同。在第 10 行用户控件重复第一个表的 id 之后。这是我的代码。

 <script type="text/javascript">

    var pageIndex = 1;
    var pageCount;
    $(window).scroll(function () {
        if ($(window).scrollTop() == $(document).height() - $(window).height()) {
            GetRecords();
        }
    }); 

    function GetRecords() {
        pageIndex++;
        if (pageIndex == 2 || pageIndex <= pageCount) {
            $("#loader").show();
            $.ajax({
                type: "POST",
                url: 'CS.aspx/GetCustomers',
                data: '{pageIndex: ' + pageIndex + '}',
                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);
        pageCount = parseInt(xml.find("PageCount").eq(0).find("PageCount").text());
        var customers = xml.find("Customers");
        customers.each(function () {
            var customer = $(this);
            var table = $("#dvCustomers table").eq(0).clone(true);
            $(".name", table).html(customer.find("Title").text());
            $(".city", table).html(customer.find("Description").text());
            $(".postal", table).html(customer.find("UserID").text());
            $(".country", table).html(customer.find("EmailID").text());
            $(".phone", table).html(customer.find("Status").text());
            $(".fax", table).html(customer.find("UserID").text());
                 $(".MainCommentscont", table).html(customer.find("ID").text());
                   $(".MainComments", table).html(customer.find("ID").text());

            $("#dvCustomers").append(table).append("<br />");
        });
        $("#loader").hide();
    }

    </script>

我希望这个 ID 应该与表(内部重复器)和用户控件绑定,并且不应该在第 10 行之后重复。

 <form id="form1" runat="server">
    <table>
        <tr>
            <td>
                <div id="dvCustomers">
                    <asp:Repeater ID="rptCustomers" runat="server">
                        <ItemTemplate>
                            <table cellpadding="2" cellspacing="0" border="1" style="width: 200px; height: 100px;
                                border: dashed 2px #04AFEF; background-color: #B0E2F5" class="MainCommentscont" id='<%# Eval("ID")%>'>>
                                <tr>
                                    <td>

                                                <b><u><span class="name">
                                                    <%# Eval("Status")%></span></u></b>
                                                    </td>
                                          <td>
                                                <b>Desc: </b><span class="MainComments">
                                                    <%# Eval("ID")%></span><br />
                                                <b>Desc: </b><span class="city">
                                                    <%# Eval("Description")%></span><br />
                                                <b>User: </b><span class="postal">
                                                    <%# Eval("UserID")%></span><br />
                                                <b>Email: </b><span class="country">
                                                    <%# Eval("EmailID")%></span><br />
                                                <b>point: </b><span class="phone">
                                                    <%# Eval("Status")%></span><br />
                                                <b>Fax: </b><span class="fax">
                                                    <%# Eval("UserID")%></span><br />

                                    </td>
                                </tr>
                            </table>
                            <br />
                        </ItemTemplate>
                    </asp:Repeater>
                </div>
            </td>
            <td valign="bottom">
                <img id="loader" alt="" src="loading.gif" style="display: none" />
            </td>
        </tr>
    </table>
</form>
4

1 回答 1

2

我认为问题,克隆后您不会更改表 ID。你能试试吗?

function OnSuccess(response) {
        var xmlDoc = $.parseXML(response.d);
        var xml = $(xmlDoc);
        pageCount = parseInt(xml.find("PageCount").eq(0).find("PageCount").text());
        var customers = xml.find("Customers");
        customers.each(function () {
            var customer = $(this);
            var table = $("#dvCustomers table").eq(0).clone(true);
            $(".name", table).html(customer.find("Title").text());
            $(".city", table).html(customer.find("Description").text());
            $(".postal", table).html(customer.find("UserID").text());
            $(".country", table).html(customer.find("EmailID").text());
            $(".phone", table).html(customer.find("Status").text());
            $(".fax", table).html(customer.find("UserID").text());
                 $(".MainCommentscont", table).html(customer.find("ID").text());
                   $(".MainComments", table).html(customer.find("ID").text());
//Change table ID
$(table).attr('ID',customer.find("ID").text());
//-
            $("#dvCustomers").append(table).append("<br />");
        });
        $("#loader").hide();
    }
于 2013-06-22T07:25:04.883 回答