We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

XML binding

Thread ID:

Created:

Updated:

Platform:

Replies:

121131 Nov 12,2015 06:28 PM UTC Nov 16,2015 12:43 PM UTC ASP.NET Web Forms 3
loading
Tags: Grid
Jorge Pampin
Asked On November 12, 2015 06:28 PM UTC

Hello,

How to bind the Grid with a XML returned by a PageMethod? The binding must be by javascript code and the PageMethod has parameter.

Thanks!

Jayaprakash Kamaraj [Syncfusion]
Replied On November 13, 2015 12:24 PM UTC

Hi Jorge,
We have created a sample for binding datasource for the Grid from server using “PageMethods”. Please refer to the code example.

Code Example:


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">
. . . . 
</ej:Grid>

<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>

Default.aspx.cs

[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();

        }
    }


Note: We need to convert xml data to proper json format to bind with ejGrid.

Regards,

Jayaprakash K.

Jorge Pampin
Replied On November 13, 2015 02:41 PM UTC

I'ts perfect! Thanks!

Prasanna Kumar Viswanathan [Syncfusion]
Replied On November 16, 2015 12:43 PM UTC

Hi Jorge,

We are happy that the provided solution working fine at your end.

Regards,
Prasanna Kumar N.S.V


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;