ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Server Side Paging in jQuery DataTable using jQuery AJAX and WebService in ASP.Net<p>Hi <a class="username" rel="jovceka"> jovceka</a>,</p> <p>Refer below sample.</p> <p><span style="text-decoration: underline;"><strong>Database</strong></span></p> <p>For this sample I have used of NorthWind database that you can download using the link given below.</p> <p><a href="https://www.aspsnippets.com/Articles/Install-the-Northwind-and-Pubs-Sample-Databases-in-SQL-Server-Express.aspx" target="_blank">Download Northwind Database</a></p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;script type=&#34;text/javascript&#34; src=&#34;https://code.jquery.com/jquery-1.11.1.min.js&#34;&gt;&lt;/script&gt; &lt;link rel=&#34;stylesheet&#34; type=&#34;text/css&#34; href=&#34;https://cdn.datatables.net/1.10.7/css/jquery.dataTables.min.css&#34; /&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;https://cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; $(function () { $(&#39;#tblCustomers&#39;).DataTable({ &#34;bServerSide&#34;: true, &#34;bProcessing&#34;: true, &#34;sPaginationType&#34;: &#34;full_numbers&#34;, &#34;pageLength&#34;: &#34;5&#34;, &#34;sAjaxSource&#34;: &#34;WebService.asmx/GetData&#34;, &#34;aoColumns&#34;: [ { &#34;mData&#34;: &#34;CustomerID&#34; }, { &#34;mData&#34;: &#34;ContactName&#34; }, { &#34;mData&#34;: &#34;City&#34; }, { &#34;mData&#34;: &#34;Country&#34; } ], &#34;fnServerData&#34;: function (source, data, callback) { $.ajax({ &#34;dataType&#34;: &#39;json&#39;, &#34;contentType&#34;: &#34;application/json; charset=utf-8&#34;, &#34;type&#34;: &#34;GET&#34;, &#34;url&#34;: source, &#34;data&#34;: data, &#34;success&#34;: function (response) { var json = jQuery.parseJSON(response.d); callback(json); } }); } }); }); &lt;/script&gt; &lt;table id=&#34;tblCustomers&#34;&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;CustomerID&lt;/th&gt; &lt;th&gt;ContactName&lt;/th&gt; &lt;th&gt;City&lt;/th&gt; &lt;th&gt;Country&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;/table&gt;</pre> <p><span style="text-decoration: underline;"><strong>WebServices</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Linq; using System.Web.Services; using NorthwindModel; using System.Text; using System.Web.Script.Serialization; using System.Web.Script.Services; /// &lt;summary&gt; /// Summary description for WebService /// &lt;/summary&gt; [WebService(Namespace = &#34;http://tempuri.org/&#34;)] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. [System.Web.Script.Services.ScriptService] public class WebService : System.Web.Services.WebService { [WebMethod] [ScriptMethod(UseHttpGet = true)] public string GetData(string sEcho, int iDisplayStart, int iDisplayLength) { NorthwindEntities entities = new NorthwindEntities(); sSearch = sSearch == null ? &#34;&#34; : sSearch; int totalRecord = entities.Customers.Count(); var result = (from customer in entities.Customers select customer) .OrderBy(customer =&gt; customer.CustomerID) .Skip(iDisplayStart) .Take(iDisplayLength).ToList(); JavaScriptSerializer js = new JavaScriptSerializer(); StringBuilder sb = new StringBuilder(); sb.Clear(); sb.Append(&#34;{&#34;); sb.Append(&#34;\&#34;sEcho\&#34;: &#34;); sb.Append(sEcho); sb.Append(&#34;,&#34;); sb.Append(&#34;\&#34;iTotalRecords\&#34;: &#34;); sb.Append(totalRecord); sb.Append(&#34;,&#34;); sb.Append(&#34;\&#34;iTotalDisplayRecords\&#34;: &#34;); sb.Append(totalRecord); sb.Append(&#34;,&#34;); sb.Append(&#34;\&#34;aaData\&#34;: &#34;); sb.Append(js.Serialize(result)); sb.Append(&#34;}&#34;); return sb.ToString(); } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Web Imports System.Web.Services Imports System.Web.Services.Protocols &#39; To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. &lt;System.Web.Script.Services.ScriptService()&gt; _ &lt;WebService(Namespace:=&#34;http://tempuri.org/&#34;)&gt; _ &lt;WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)&gt; _ &lt;Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()&gt; _ Public Class WebService &lt;WebMethod()&gt; &lt;ScriptMethod(UseHttpGet:=True)&gt; Public Function GetData(ByVal sEcho As String, ByVal iDisplayStart As Integer, ByVal iDisplayLength As Integer) As String Dim entities As NorthwindEntities = New NorthwindEntities() sSearch = If(sSearch Is Nothing, &#34;&#34;) Dim totalRecord As Integer = entities.Customers.Count() Dim result = (From customer In entities.Customers Select customer).OrderBy(Function(customer) customer.CustomerID).Skip(iDisplayStart).Take(iDisplayLength).ToList() Dim js As JavaScriptSerializer = New JavaScriptSerializer() Dim sb As StringBuilder = New StringBuilder() sb.Clear() sb.Append(&#34;{&#34;) sb.Append(&#34;&#34;&#34;sEcho&#34;&#34;: &#34;) sb.Append(sEcho) sb.Append(&#34;,&#34;) sb.Append(&#34;&#34;&#34;iTotalRecords&#34;&#34;: &#34;) sb.Append(totalRecord) sb.Append(&#34;,&#34;) sb.Append(&#34;&#34;&#34;iTotalDisplayRecords&#34;&#34;: &#34;) sb.Append(totalRecord) sb.Append(&#34;,&#34;) sb.Append(&#34;&#34;&#34;aaData&#34;&#34;: &#34;) sb.Append(js.Serialize(result)) sb.Append(&#34;}&#34;) Return sb.ToString() End Function End Class</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://i.imgur.com/GqmeBlW.gif" alt="" width="363" height="482" /></p>https://www.aspforums.net:443/Threads/123191/Server-Side-Paging-in-jQuery-DataTable-using-jQuery-AJAX-and-WebService-in-ASPNet/https://www.aspforums.net:443/Threads/123191/Server-Side-Paging-in-jQuery-DataTable-using-jQuery-AJAX-and-WebService-in-ASPNet/Fri, 05 Jul 2019 08:07:33 GMT