Bind Content of page on scrolling using asp.net c#

Bind Content of page on scrolling using asp.net c# 


.Aspx Page

<head id="Head1" runat="server">
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script>
        $(function () {
            InfiniteScroll();
        });
        function InfiniteScroll() {
            $('#divPostsLoader').html('<img src="images/loader.gif">');

            //send a query to server side to present new content
            $.ajax({
                type: "POST",
                url: "scroll.aspx/GetData",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    if (data != "") {
                        debugger;
                        $('.divLoadData:last').after(data.d);
                    }
                    $('#divPostsLoader').empty();
                }
            })
        };

        $(window).scroll(function () {
            if ($(window).scrollTop() == $(document).height() - $(window).height()) {
                InfiniteScroll();
            }
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="divLoadData" class="divLoadData">
   
    </div>
    </form>
</body>
</html>


.CS Code :-


static int RecordCount, FirstCount = 0;

       [WebMethod]
        public static string GetData()
        {
            RecordCount = RecordCount + 10;
            DataTable dt = new DataTable();
            string Sql = "SELECT complaint_id,Cust_Lat_Code,Cust_Long_Code,Address FROM Complaint_Log WHERE Cust_Lat_Code IS NOT NULL   ORDER BY complaint_id OFFSET " + FirstCount + " ROWS FETCH NEXT 10 ROWS ONLY";
            FirstCount = RecordCount;
            StringBuilder sb = new StringBuilder();
            dt = new DataTable();
            SQLHelper sq = new SQLHelper();
            DataSet ds = sq.RunSqlReturnDs(Sql);
            dt = ds.Tables[0];
            DataView dv = dt.DefaultView;

            foreach (DataRowView row in dv)
            {
                sb.AppendFormat("<p>lat " + " <strong>" + row["Cust_Lat_Code"] + "</strong>");
                sb.AppendFormat("<p>Long" + " <strong>" + row["Cust_Long_Code"] + "</strong>");
                sb.AppendFormat("<p>Address" + " <strong>" + row["Address"] + "</strong>");
                sb.AppendFormat("<hr/>");
            }

            sb.AppendFormat("<divstyle='height:15px;'></div>");
            return sb.ToString();
        }

Comments

Popular posts from this blog

Create and save QR code in asp.net with C#

Change text of RadGrid Header Dynamically

Telerik Radwindow Open on Button Click