Category / Section
How to bind webservice to grid using the ASP.NET webservice
1 min read
How to successfully bind the data to Grid Control from ASP.Net WebService.
Solution
By using “WebMethodAdaptor” we can bind data from Webservice to Grid Control and also we need to uncomment or include the “ScriptService” Attribute to WebService in order to enable request from client-side.
<ej:Grid ID="OrdersGrid" runat="server" AllowPaging="True"> <PageSettings PageSize="5" /> <DataManager URL="WebService1.asmx/Get" Adaptor="WebMethodAdaptor" /> </ej:Grid>
namespace Sample { /// <summary> /// Summary description for WebService1 /// </summary> // 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 WebService1 : System.Web.Services.WebService { [WebMethod] public object Get(DataManager value) { var data = (from ord in new DataClasses1DataContext().Orders.Take(200) select new EditableOrder { OrderID = ord.OrderID, OrderDate = ord.OrderDate, CustomerID = ord.CustomerID, EmployeeID = ord.EmployeeID, Freight = ord.Freight, ShipAddress = ord.ShipAddress, ShipCity = ord.ShipCity, ShipName = ord.ShipName, ShipPostalCode = ord.ShipPostalCode, ShipRegion = ord.ShipRegion, ShipCountry = ord.ShipCountry }).ToList(); var count = data.Count; data = data.Skip(value.Skip).Take(value.Take).ToList(); return new {result = data, count = count }; } } }
The following output is displayed as a result of above code example.