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

Basic grid datasource in webform Web Services problem

2 Answers 77 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Yoav
Top achievements
Rank 1
Yoav asked on 05 Feb 2014, 04:54 PM
Hi,

I’m testing kendo grid and trying to get it to read from asp.net WebMethod in a webform.  I’ve tried many options in the code but nothing works. How can I return the correct json format for the grid to use?

[WebMethod]         
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string GetSomthing() {

 // [{"ProductID":1,"ProductName":"Test Product"}]

}




I have the following script in the aspx page:


<script src="http://cdn.kendostatic.com/2013.3.1324/js/jquery.min.js"></script>
<link href="http://cdn.kendostatic.com/2013.3.1324/styles/kendo.common.min.css" rel="stylesheet" />
<link href="http://cdn.kendostatic.com/2013.3.1324/styles/kendo.default.min.css" rel="stylesheet" />
<script src="http://cdn.kendostatic.com/2013.3.1324/js/kendo.web.min.js"></script>


<div id="example" class="k-content">
        <div id="grid"> </div>
        <script>



            $(document).ready(function () {
                
                $("#grid").kendoGrid({
                    dataSource: {
                        transport: {
                            read: {                                
                                url: "KendoTest.aspx/GetSomthing", 
                                dataType: "json",
                                type: "POST",
                                data: {}
                            }
                            
                        },
                        schema: {
                            data: "d",
                            model: {
                                id: "ProductID",
                                fields: {
                                    ProductID: { editable: true, type: "number" },
                                    ProductName: { editable: true, type: "string" }
                                }
                            }
                        }
                    },
                    height: 250,
                    columns: [{
                        field: "ProductID"
                    }, {
                        field: "ProductName"
                    }]
                });
            });


        </script>
    </div>





Thanks.

2 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 07 Feb 2014, 11:52 AM
Hello,

You should return a collection of objects instead of a string. Please check this code-library which demonstrates binding the Grid to data loaded from page methods.

Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Yoav
Top achievements
Rank 1
answered on 09 Feb 2014, 05:29 PM
Thanks Daniel. My problem was actually the need to change the returned object to json notation. Using the following solved my problem:
 
parameterMap: function (options, operation) {
                            return kendo.stringify(options);
                        }
Tags
Grid
Asked by
Yoav
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Yoav
Top achievements
Rank 1
Share this question
or