Site.Master
<%--Enable PagerMethods--%> <asp:ScriptManager runat="server" EnablePageMethods="true"> </asp:ScriptManager>
Default.aspx <ej:Button Type="Button" runat="server" ClientSideOnClick="btnClick" Text="button"></ej:Button> <ej:Grid ID="FlatGrid" runat="server" AllowSorting="True" AllowPaging="True"> <script type="text/javascript">
function btnClick(args) { PageMethods.GetCityNameArray(keyvalue, OnSuccessGetCityNameArray); } function OnSuccessGetCityNameArray(response) { // here we get xml data var jsondata = …;// here We want to change xmltojson var gridObj = $('#<%= OrdersGrid.ClientID %>').data("ejGrid"); gridObj.dataSource(jsondata); }
</script> [System.Web.Services.WebMethod] public static object GetCityNameArray(string[] cities) { var data = new NorthwndDataContext().Orders.Take(10).ToList(); var count = new NorthwndDataContext().Orders.Count(); var xmlString = GetXMLString(data, count); return xmlString; } public static string GetXMLString(IEnumerable<Order> list, int count) {
var xml = new XElement("Orders", from ord in list select new XElement("Order", new XElement("OrderID", ord.OrderID), new XElement("EmployeeID", ord.EmployeeID), new XElement("CustomerID", ord.CustomerID), new XElement("Freight", ord.Freight), new XElement("ShipName", ord.ShipName) ), new XElement("Count", count)); return xml.ToString(); } |