将数据绑定到jqgrid时出现问题

问题描述:

这是客户端代码

hi here is client side code

<script src="Scripts/jquery-1.6.2.js" type="text/javascript"></script>
<script src="JavaScript/grid.locale-en.js" type="text/javascript"></script>
<script src="JavaScript/jquery.jqGrid.min.js" type="text/javascript"></script>
    <script src="JavaScript/json2-min.js" type="text/javascript"></script>
<script type="text/javascript">
    function successFunction(jsondata, a) {
  var thegrid = jQuery("#productGridView")[0];
        var data = JSON.stringify(jsondata);
       thegrid.addJSONData(JSON.parse(data));

    }
  function getProducts() {

        var PolicyNumberorClaim = $("#txtPolicyNum").val();
        var PolicyNum = { PolicyNo: PolicyNumberorClaim };


        $.ajax({
            url: "Service/RGIService.svc/ServiceRequestListByPolNumber",
            data: JSON.stringify(PolicyNum),  // For empty input data use "{}",
            dataType: "json",
            type: "POST",
            contentType: "application/json; charset=utf-8",
            success: successFunction
        });
    }

    function dataBindToGrid() {
        jQuery("#productGridView").jqGrid({
            datatype: getProducts,
            colNames: ['SRNo', 'ClaimNo', 'SubCategory', 'PolicyNumber', 'ExpectedClosureDateSpecified'],
            colModel: [{ name: 'SRNo', index: 'SRNo', width: 200, align: 'left' },
                        { name: 'ClaimNo', index: 'ClaimNo', width: 200, align: 'left' },

                        { name: 'SubCategory', index: 'SubCategory', width: 200, align: 'left' },
                        { name: 'PolicyNumber', index: 'PolicyNumber', width: 200, align: 'left' },
                        { name: 'ExpectedClosureDateSpecified', index: 'ExpectedClosureDateSpecified', width: 200, align: 'left' }
                       ],
            rowNum: 10,
            rowList: [5, 10, 20, 50, 100],
            sortname: 'SRNo',
            pager: jQuery('#pageNavigation'),
            sortorder: "desc",
            viewrecords: true
        });
    }
    $(document).ready(function () {

        $("input#LoadData").live("click", dataBindToGrid);
    });
</script>
<link rel="stylesheet" type="text/css" media="screen" href="css/redmond/jquery-ui-1.7.2.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />


<div>
        <table id="productGridView" class="scroll">
        </table>
        <input type="text" name="PolicyNumber" placeholder="Enter Policy Number" id="txtPolicyNum"
            maxlength="16" />
        <div id="pageNavigation" class="scroll" style="text-align: center;">
        </div>
        <input type="button" id="LoadData" value="LoadData"  önclick="dataBindToGrid();" />
       
    </div>


服务代码为


and the service code will be

public string ServiceRequestListByPolNumber(String PolicyNo)
{
    PortalService.ServiceRequestDetails[] objPolicyDetails = new PortalService.ServiceRequestDetails[0];
    List<string> objString = new System.Collections.Generic.List<string>();
    List<SelectList> list = new List<SelectList>();
    try
    {
        PortalService.WCFServiceClient obj = new PortalService.WCFServiceClient();
       PortalService.WCFServiceClient();

        objPolicyDetails = obj.GetServiceRequestListByPolicyNo(PolicyNo);
        List<rgipolicydetails> lstpol = new System.Collections.Generic.List<rgipolicydetails>();
        RGIPolicyDetails pol = new RGIPolicyDetails();
        foreach (PortalService.ServiceRequestDetails sr in objPolicyDetails)
        {

            pol.ClaimNo = sr.Category;
            pol.CreateDate = sr.CreateDate.ToString();
            pol.ExpectedClosureDate = sr.ExpectedClosureDate.ToString();
            pol.ExpectedClosureDateSpecified = sr.ExpectedClosureDateSpecified.ToString();
            pol.PolicyNumber = sr.PolicyNumber;
            pol.SRNo = sr.SRNo;
            pol.SubCategory = sr.SubCategory;
        }
        return pol.TOJSON();
    }
    catch (Exception ex)
    {
        return null;
    }
}


而课程将是


and the class will be

public abstract class JqGridView
{

    public abstract string ToJson();
}

public  class RGIPolicyDetails 
{
    public string PolicyNo { get; set; }
    public string InsuredNameFore { get; set; }
    public string InsuredNameLast { get; set; }
    public string PolicyPeriod{ get; set; }
    public string VehiceMakeorModel{ get; set; }
      public string  VehicleNumber{ get; set; }
      public string PolicyCoverFrom { get; set; }
      public string PolicyCoverTo { get; set; }

       public string   ClaimNo{ get; set; }
    public string CreateDate{ get; set; }
    public string ExpectedClosureDate{get;set;}
        public string  ExpectedClosureDateSpecified{ get; set; }
         public string     PolicyNumber{ get; set; }

           public string   SRNo{ get; set; }
           public string SubCategory { get; set; }
           public string status { get; set; }

        
}


public static class methodtest 
{
       public static string TOJSON(this object obj)
{

JavaScriptSerializer serializer=new JavaScriptSerializer();
return serializer.Serialize(obj);
}
        
}


谁能建议我我要去哪里哪里


can any one suggest me where i am going wrong

(" ).val(); var PolicyNum = {PolicyNo:PolicyNumberorClaim};
("#txtPolicyNum").val(); var PolicyNum = { PolicyNo: PolicyNumberorClaim };


.ajax({ url:" , 数据: JSON .stringify(PolicyNum),// 对于空的输入数据使用"{}", dataType:" , 类型:" , contentType:" , 成功:successFunction }); } 函数 dataBindToGrid(){ jQuery(" ).jqGrid({ 数据类型:getProducts, colNames:[' SRNo'' ClaimNo'' SubCategory'' PolicyNumber'' ExpectedClosureDateSpecified'], colModel:[{名称:' SRNo',索引: ' SRNo',宽度: 200 ,对齐:左'}, {名称:' ClaimNo',索引:' ClaimNo',宽度: 200 ,对齐:' 左'}, {名称:' SubCategory',索引:' SubCategory',宽度: 200 ,对齐:' 左'}, {名称:' PolicyNumber',索引:' PolicyNumber',宽度: 200 ,对齐:' 左'}, {名称:' ExpectedClosureDateSpecified',索引:' ExpectedClosureDateSpecified',宽度: 200 ,对齐:' 左'} ], rowNum: 10 , rowList:[ 5 10 20 50 100 ], sortname:' SRNo', 传呼机:jQuery(' #pageNavigation'), 排序顺序:" , viewrecords: true }); }
.ajax({ url: "Service/RGIService.svc/ServiceRequestListByPolNumber", data: JSON.stringify(PolicyNum), // For empty input data use "{}", dataType: "json", type: "POST", contentType: "application/json; charset=utf-8", success: successFunction }); } function dataBindToGrid() { jQuery("#productGridView").jqGrid({ datatype: getProducts, colNames: ['SRNo', 'ClaimNo', 'SubCategory', 'PolicyNumber', 'ExpectedClosureDateSpecified'], colModel: [{ name: 'SRNo', index: 'SRNo', width: 200, align: 'left' }, { name: 'ClaimNo', index: 'ClaimNo', width: 200, align: 'left' }, { name: 'SubCategory', index: 'SubCategory', width: 200, align: 'left' }, { name: 'PolicyNumber', index: 'PolicyNumber', width: 200, align: 'left' }, { name: 'ExpectedClosureDateSpecified', index: 'ExpectedClosureDateSpecified', width: 200, align: 'left' } ], rowNum: 10, rowList: [5, 10, 20, 50, 100], sortname: 'SRNo', pager: jQuery('#pageNavigation'), sortorder: "desc", viewrecords: true }); }


(文档).ready( function (){
(document).ready(function () {