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. Image for the cookie policy date

Grid control: Binding with a System.Data.DataTable object

Hello,

If I bind my grid control with a System.Data.DataTable object by code behind there is no problem:

this.GdCuentas.DataSource = EA.ObtenerTabla(tipoEntidad);
this.GdCuentas.DataBind();

But, if I bind my grid control by WebMethod and WebMethodAdaptor it doesn't work:

 [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public static object GetRecursos(Syncfusion.JavaScript.DataManager value,Guid idPadre, string sesion)
        {
            DataResult result = new DataResult();

                SAVE.SAVEDMDB.Sesion.EscenarioAbierto EA = System.Web.HttpContext.Current.Session[sesion] as SAVE.SAVEDMDB.Sesion.EscenarioAbierto;

                SAVE.SAVEDMDB.DataModel.DsEscenario.RecursosDataTable RDT = EA.ObtenerTabla(SAVE.SAVECommon.TipoEntidad.Recursos) as SAVE.SAVEDMDB.DataModel.DsEscenario.RecursosDataTable;

                result.result = RDT;
                result.count = RDT.Rows.Count;
 

            return result;
        }

Why?

Thanks!

1 Reply

PK Prasanna Kumar Viswanathan Syncfusion Team November 12, 2015 03:54 PM UTC

Hi Jorge,

 

Thanks for contacting Syncfusion support.

 

While using webMethod Adapter, we suggest you to convert data table to list before assigning data to the grid.

 

Please find the code example and sample:

 

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
 
    <ej:Grid ID="FlatGrid" runat="server" AllowSorting="True" AllowGrouping="true" AllowPaging="True">
        <DataManager Adaptor="WebMethodAdaptor" URL="/Default.aspx/Data"/>
           <EditSettings AllowEditing="True" AllowAdding="True" AllowDeleting="True"></EditSettings>
           <ToolbarSettings ShowToolbar="True" ToolbarItems="add,edit,delete,update,cancel"></ToolbarSettings>
            <Columns>
                <ej:Column Field="OrderID" HeaderText="Order ID" IsPrimaryKey="True" TextAlign="Right" Width="100" />
                <ej:Column Field="CustomerID" HeaderText="Customer ID" Width="100" />
                <ej:Column Field="EmployeeID" HeaderText="Employee ID" TextAlign="Right" Width="100" />
            </Columns>
        </ej:Grid>
    <asp:SqlDataSource ID="SqlData" runat="server" ConnectionString="<%$ ConnectionStrings:NORTHWNDConnectionString %>"
            SelectCommand="SELECT * FROM [Orders]"></asp:SqlDataSource>  
</asp:Content>
 
-----------------------------------------------------------------------------
public static object Data(Syncfusion.JavaScript.DataManager value)
        {
            var data = GetGridDT();
            DataResult ds = new DataResult();
            DataOperations obj = new DataOperations();
            var emp = (from DataRow row in data.Rows
                       select new OrderTable
                       {
                           OrderID = Convert.ToInt32(row["OrderID"]),
                           CustomerID = row["CustomerID"].ToString(),
                           EmployeeID = Convert.ToInt32(row["EmployeeID"]),
                           ShipCountry = row["ShipCountry"].ToString()
 
                       }).ToList();
            ds.result = obj.Execute(emp, value);
            ds.count = emp.Count;
            return ds;
        }

 

Sample: http://www.syncfusion.com/downloads/support/forum/121099/ze/WebApplication211928991356

 

Regards,

Prasanna Kumar N.S.V


Loader.
Live Chat Icon For mobile
Up arrow icon