This is a migrated thread and some comments may be shown as answers.

Grid Is not Showing Data

2 Answers 513 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Rahul
Top achievements
Rank 1
Rahul asked on 02 Apr 2012, 05:48 AM
in Default.aspx

<script type="text/javascript">
        var dataSource = new kendo.data.DataSource(
            {
                transport: {
                    read: {
                        contentType: "application/json; charset=utf-8",
                        type: "POST",
                        dataType: "json",
                        url: "http://localhost:1249/KendoUI2nd/WebService.asmx/LoadData"                        
                    }
                },
                pageSize: 10,
                schema: {
                    model: {
                        fields: {
                            Pkid_Emp: { type: "number" },
                            fkid_Dept: { type: "string" },
                            txt_Name: { type: "string" },
                            txt_Address: { type: "string" },
                            txt_Phone: { type: "string" },
                            txt_Salary: { type: "string" }
                        }
                    }
                }
            });
        alert(dataSource);

        $(document).ready(function () {
            $("#myGrid").kendoGrid({
                dataSource: dataSource,
                height: 250,
                columns: [
                 { field: "Pkid_Emp", title: "Pkid_Emp" },
                 { field: "fkid_Dept", title: "fkid_Dept" },
                 { field: "txt_Name", title: "txt_Name" },
                 { field: "txt_Address", title: "txt_Address" },
                 { field: "txt_Phone", title: "txt_Phone" },
                 { field: "txt_Salary", title: "txt_Salary" }
                        ]
            });
        });
    </script>

 <div>
            <div id="myGrid">
            </div>
        </div>


in Webservice.cs

[WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string LoadData()
    {
        MyDataClassesDataContext MyDB = new MyDataClassesDataContext();

        var sharedDataSource1 = from x in MyDB.Emps
                                  select x;

        var serializer = new JavaScriptSerializer();

        return serializer.Serialize(sharedDataSource1);
    }



when is called webservice i get JSON Data . still my grid is empty . Please Help me ...






Thanks i read ur example n i implement read() into my project
but it showing me
System.NotSupportedException: Cannot serialize interface System.Collections.Generic.IEnumerable`1[[EmployeeClass, App_Code.7o30vskr, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]].
   at System.Xml.Serialization.TypeDesc.CheckSupported()
   at System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference, Boolean throwOnError)
   at System.Xml.Serialization.ModelScope.GetTypeModel(Type type, Boolean directReference)
   at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(Type type, XmlRootAttribute root, String defaultNamespace)
   at System.Web.Services.Protocols.XmlReturn.GetInitializers(LogicalMethodInfo[] methodInfos)
   at System.Web.Services.Protocols.XmlReturnWriter.GetInitializers(LogicalMethodInfo[] methodInfos)
   at System.Web.Services.Protocols.MimeFormatter.GetInitializers(Type type, LogicalMethodInfo[] methodInfos)
   at System.Web.Services.Protocols.HttpServerType..ctor(Type type)
   at System.Web.Services.Protocols.HttpServerProtocol.Initialize()
   at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)

I Dont Know why ???? 
Please Help Me ... 

2 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 02 Apr 2012, 07:38 AM
Hello,

Your web method is not properly configured. It should not serialize the result as JSON because the framework already does that.

 Here is a runnable project showing binding a Kendo Grid to an ASMX service: https://github.com/telerik/kendo-examples-asp-net/tree/master/grid-web-service-crud 


Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Rahul
Top achievements
Rank 1
answered on 02 Apr 2012, 02:06 PM
Thanks I got The Answer...................
Tags
Data Source
Asked by
Rahul
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Rahul
Top achievements
Rank 1
Share this question
or