C# 将XML从Web服务读取到datagrid,但可以´;t用这些值填充Kendogrid

C# 将XML从Web服务读取到datagrid,但可以´;t用这些值填充Kendogrid,c#,json,xml-serialization,kendo-grid,telerik-grid,C#,Json,Xml Serialization,Kendo Grid,Telerik Grid,我想尝试使用剑道网格。我有以下css和js文件 <link href="../Content/kendo/2014.1.318/kendo.common.min.css" rel="stylesheet" type="text/css" /> <link href="../Content/kendo/2014.1.318/kendo.default.min.css" rel="stylesheet" type="text/css" /> <script src=".

我想尝试使用剑道网格。我有以下css和js文件

<link href="../Content/kendo/2014.1.318/kendo.common.min.css" rel="stylesheet" type="text/css" />
<link href="../Content/kendo/2014.1.318/kendo.default.min.css" rel="stylesheet" type="text/css" />
<script src="../Scripts/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="../Scripts/kendo/2014.1.318/kendo.web.min.js" type="text/javascript"></script>
而我的cs作为

 [WebMethod(EnableSession = true)]
public string BindCreatedGrid(string status)
{
    Login l = new Login();
    long userId = l.UserId;

    if (userId != 0)
    {
        TransferRequestMethods trm = new TransferRequestMethods();
        status = GetStatus(status);
        DataSet dsResult = trm.GetCreatedHardwareTransferRequestList(status, userId);
        return dsResult.GetXml();
    }
    else
    {
        return "Expired";
    }
}

值被返回到kendogrid,但它没有绑定任何值。我不知道它是否应该转换为json或如何转换。我与kendo合作的时间不长,但我遇到了类似的问题,所以我所做的是在数据源中定义模式,然后绑定工作:)

回答我自己的问题(感谢毗瑟奴:))。 我不知道这是否是正确的方法,但它对我有效

首先在我的cs中,我将xml作为字符串返回

 public string BindCreatedGrid(string status)
{
    Login l = new Login();
    long userId = l.UserId;

    if (userId != 0)
    {
        TransferRequestMethods trm = new TransferRequestMethods();
        status = GetStatus(status);
        DataSet dsResult = trm.GetCreatedHardwareTransferRequestList(status, userId);
        string s =dsResult.GetXml();
        return s;
    }
    else
    {
        return "Expired";
    }
}
然后在html中我给出了

   var data = "";
      $.ajax({
          type: "POST",
          url: "../Transfer/Transfer_Services/Transfer.asmx/BindCreatedGrid",
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          data: JSON.stringify({ status: 'RequestState' }),
          success: function (result) {
              debugger;

              data = result.d;
              $("#grid").kendoGrid({

                  dataSource: {
                      transport: {

                          read: function (options) {
                              options.success(data);
                          }
                      },
                      schema: {
                          type: "xml",
                          data: "/NewDataSet/myTable",
                          model: {
                              // configure the fields of the object                                  
                              fields: {
                                  // the "title" field is mapped to the text of the "title" XML element
                                  TransferId: "TransferId/text()",
                                  // the "title" field is mapped to the text of the "title" XML element
                                  AssetId: "AssetId/text()",
                                  // the "title" field is mapped to the text of the "title" XML element
                                  AssetName: "AssetName/text()",
                                  // the "title" field is mapped to the text of the "title" XML element
                                  DMName: "DMName/text()",
                                  // the "title" field is mapped to the text of the "title" XML element
                                  ToUser: "ToUser/text()",
                                  // the "title" field is mapped to the text of the "title" XML element
                                  Status: "Status/text()",
                                  // the "title" field is mapped to the text of the "title" XML element
                                  Details: "Details/text()",
                                  // the "title" field is mapped to the text of the "title" XML element
                                  Verify: "Verify/text()",
                                  // the "title" field is mapped to the text of the "title" XML element
                                  Delete: "Delete/text()"

                              }
                          }
                      },
                      pageSize: 20
                  },
                  sortable: true,
                  filterable: true,
                  reorderable: true,
                  navigatable: true,
                  selectable: "multiple",
                  columnMenu: true,
                  resizable: true,
                  pageable: {
                      refresh: true,
                      pageSizes: true,
                      buttonCount: 8
                  },
                  columns: [
                            {
                                field: "TransferRequestId",
                                title: "Request Id"
                            },
                            {
                                field: "AssetId",
                                title: "Asset Id"
                            },
                            {
                                field: "AssetName",
                                title: "Asset Name"
                            },
                            {
                                field: "DMName",
                                title: "DM Name"
                            },
                            {
                                field: "ToUserName",
                                title: "To User"
                            },
                            {
                                field: "StatusName",
                                title: "Status"
                            },
                            {
                                field: "Details",
                                title: "Details",
                                template: kendo.template($("#ActionLinkDetails").html())

                            },
                            {
                                field: "Verify",
                                title: "Verify",
                                template: kendo.template($("#ActionLinkVerify").html())
                            },
                            {
                                field: "Delete",
                                title: "Delete",
                                template: kendo.template($("#ActionLinkDelete").html())
                            }
                            ]
              });
              // options.success(result);                
          }

这对我很管用。。还有别的办法吗?任何新方法都值得赞赏:)

您试图绑定到网格的xml的结构是什么?当映射到xml源时,您需要为要绑定的元素/属性提供所需的xpath。如果您可以为数据源共享您的代码,这将非常有用
   var data = "";
      $.ajax({
          type: "POST",
          url: "../Transfer/Transfer_Services/Transfer.asmx/BindCreatedGrid",
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          data: JSON.stringify({ status: 'RequestState' }),
          success: function (result) {
              debugger;

              data = result.d;
              $("#grid").kendoGrid({

                  dataSource: {
                      transport: {

                          read: function (options) {
                              options.success(data);
                          }
                      },
                      schema: {
                          type: "xml",
                          data: "/NewDataSet/myTable",
                          model: {
                              // configure the fields of the object                                  
                              fields: {
                                  // the "title" field is mapped to the text of the "title" XML element
                                  TransferId: "TransferId/text()",
                                  // the "title" field is mapped to the text of the "title" XML element
                                  AssetId: "AssetId/text()",
                                  // the "title" field is mapped to the text of the "title" XML element
                                  AssetName: "AssetName/text()",
                                  // the "title" field is mapped to the text of the "title" XML element
                                  DMName: "DMName/text()",
                                  // the "title" field is mapped to the text of the "title" XML element
                                  ToUser: "ToUser/text()",
                                  // the "title" field is mapped to the text of the "title" XML element
                                  Status: "Status/text()",
                                  // the "title" field is mapped to the text of the "title" XML element
                                  Details: "Details/text()",
                                  // the "title" field is mapped to the text of the "title" XML element
                                  Verify: "Verify/text()",
                                  // the "title" field is mapped to the text of the "title" XML element
                                  Delete: "Delete/text()"

                              }
                          }
                      },
                      pageSize: 20
                  },
                  sortable: true,
                  filterable: true,
                  reorderable: true,
                  navigatable: true,
                  selectable: "multiple",
                  columnMenu: true,
                  resizable: true,
                  pageable: {
                      refresh: true,
                      pageSizes: true,
                      buttonCount: 8
                  },
                  columns: [
                            {
                                field: "TransferRequestId",
                                title: "Request Id"
                            },
                            {
                                field: "AssetId",
                                title: "Asset Id"
                            },
                            {
                                field: "AssetName",
                                title: "Asset Name"
                            },
                            {
                                field: "DMName",
                                title: "DM Name"
                            },
                            {
                                field: "ToUserName",
                                title: "To User"
                            },
                            {
                                field: "StatusName",
                                title: "Status"
                            },
                            {
                                field: "Details",
                                title: "Details",
                                template: kendo.template($("#ActionLinkDetails").html())

                            },
                            {
                                field: "Verify",
                                title: "Verify",
                                template: kendo.template($("#ActionLinkVerify").html())
                            },
                            {
                                field: "Delete",
                                title: "Delete",
                                template: kendo.template($("#ActionLinkDelete").html())
                            }
                            ]
              });
              // options.success(result);                
          }