如何从客户端将数据附加到转发器控件

时间:2016-03-08 11:02:38

标签: c# jquery html arrays

我想将数据附加到转发器,转发器已经在页面加载时有一些数据。但我想在滚动页面时重新加载数据。

<script type="text/javascript">


        $(window).scroll(function () {
            if ($(window).scrollTop() + $(window).height() == $(document).height()) {
                showData();
            }
        });


        function showData() {
            PageMethods.getData(onSuccess, onError);  // getData is a page webmethod thats return five record in json string.
            function onSuccess(data) {
                alert(data); // data has all five record.
            }
            function onError(data) {
                alert('Problem');
            }
        }

    </script>

.NET

        <div id="Posts" class="container-fluid padded">
            <asp:Repeater ID="PostsRepeater" runat="server">
                <ItemTemplate>
                    <section>
                        <div class="col-md-2">
                            <img src="images/" <%#("ImagePath") %> alt="<%#Eval("username") %>" class="img-circle img-responsive" />
                        </div>
                        <div class="col-md-10">
                            <div>
                                <b><%#Eval("username") %></b><p><span class="glyphicon glyphicon-time"></span>Posted on Feb <%#Eval("CreationDate") %></p>
                            </div>
                            <hr>
                            <p><%#Eval("Status") %></p>
                            <img src="images/1451285316491.jpg" class="img-responsive">
                        </div>
                        <div class="row commentbox">
                            <div class="col-sm-2">
                                <div class="thumbnail">
                                    <img class="img-responsive user-photo img-circle" src="images/1451285316491.jpg">
                                </div>
                                <!-- /thumbnail -->
                            </div>
                            <!-- /col-sm-1 -->
                            <div class="col-sm-10">
                                <div class="panel panel-default">
                                    <div class="panel-heading">
                                        <strong>Ali</strong> <span class="text-muted">commented 5 days ago</span>
                                    </div>
                                    <div class="panel-body">
                                        This Is awsome post
                                    </div>
                                    <!-- /panel-body -->
                                </div>
                                <!-- /panel panel-default -->
                            </div>
                            <!-- /col-sm-6 -->
                        </div>
                        <!-- /row commentbox -->
                    </section>
                </ItemTemplate>
            </asp:Repeater>
            <img id="loader" class="img-responsive col-md-offset-4" alt="" src="images/loading.gif" style="display:none" />
        </div>

1 个答案:

答案 0 :(得分:0)

在窗口滚动中,您可以创建 jQuery Ajax call which returns data ,并且在成功方法上获取响应并将其绑定到您的父Div Posts(即重复控件)

编辑:绑定数据的代码.i.e(Ajax成功方法)

function OnSuccess(response) {
    var items = response.d;
    var fragment='';
    $.each(items, function (index, val) {

    var aData_imgSRC= val.imgSRC;
    var aData_USERNAME= val.USERNAME;        

     // ..... 

   fragment += "<section> <div class='col-md-2'>  <img src='"+aData_imgSRC+"'   class='img-circle img-responsive' />  </div>   <div class='col-md-10'>    <div>   <b>"+aData_USERNAME+"</b><p><span class='glyphicon glyphicon-time'></span>Posted on Feb "+aData_Date+"></p> </div>  <hr>   <p>"+aData_Status+"</p>    <img src='images/1451285316491.jpg' class='img-responsive'></div>  </section>";
    });
    $('#Posts').append(fragment);
}

链接:How to consume Webmethod in Asp.net C#