1

I have a Jqgrid that i am trying to load with server side Json data data is not getting loaded into Jqgrid.I am not getting any error either.

This is my client side code..

function getdata() {
    $("#UsersGrid").jqGrid({
        url: 'getGriddahico.ashx',
        datatype: 'json',
        colNames: ['AccountNumber', 'BillNumber', 'BillDate', 'Oprator', 'CallDate', 'Time', 'Destination', 'DialledNumber', 'CallType', 'Duration', 'CallCost', 'PhoneNumber'],
        colModel: [
            { name: 'AccountNumber', width: 100, sortable: true, align: 'center' },
            { name: 'BillNumber', width: 100, sortable: true, align: 'center' },
            { name: 'BillDate', width: 100, sortable: true, align: 'center' },
            { name: 'Oprator', width: 100, sortable: true },
            { name: 'CallDate', width: 100, sortable: true, align: 'center' },
            { name: 'Time', width: 100, sortable: true, align: 'center' },
            { name: 'Destination', width: 100, sortable: true, align: 'center' },
            { name: 'DialledNumber', width: 100, sortable: true, align: 'center' },
            { name: 'CallType', width: 100, sortable: true, align: 'center' },
            { name: 'Duration', width: 100, sortable: true, align: 'center' },
            { name: 'CallCost', width: 100, sortable: true, align: 'center' },
            { name: 'PhoneNumber', width: 100, sortable: true, align: 'center' }   
            ],
            rowNum: 100,
            rowList: [100, 200, 300],
            pager: '#UsersGridPager',
            sortname: 'CallDate',
            viewrecords: true,
            ignoreCase: true,
            sortorder: 'asc',
            autowidth: true,
            toppager: true,
            height: '100%'
});

And this is my client side code to get the data in json format..

while(rs.Read()){
    if(rc){
        json = json + ",";
    }

    json = json + "\n{";
    json = json + "\"CallCost\":\"" + Convert.ToString(rs["CallCost"]) + "\",";
    json = json + "\"cell\":[" + Convert.ToString(rs["CallCost"]) + "";
    json = json + ",\"" + Convert.ToString(rs["AccountNumber"]) + "\"";
    json = json + ",\"" + Convert.ToString(rs["BillNumber"]) + "\"";
    json = json + ",\"" + Convert.ToString(rs["BillDate"]) + "\"";
    json = json + ",\"" + Convert.ToString(rs["Oprator"]) + "\"";
    json = json + ",\"" + Convert.ToString(rs["CallDate"]) + "\"";
    json = json + ",\"" + Convert.ToString(rs["Time"]) + "\"";
    json = json + ",\"" + Convert.ToString(rs["Destination"]) + "\"";
    json = json + ",\"" + Convert.ToString(rs["DialledNumber"]) + "\"";
    json = json + ",\"" + Convert.ToString(rs["CallType"]) + "\"";
    json = json + ",\"" + Convert.ToString(rs["Duration"]) + "\"";
    json = json + ",\"" + Convert.ToString(rs["CallCost"]) + "\"";
    json = json + ",\"" + Convert.ToString(rs["PhoneNumber"]) + "\"]";
    json = json + "}";

    rc=true;
}

json = json +"]\n";

json = json +"}";

HttpContext.Current.Response.Write(json);

Please help me to resolve the issue .Thanks..

Paul Zahra
  • 9,522
  • 8
  • 54
  • 76
user3924730
  • 163
  • 1
  • 3
  • 14
  • Do you use Glimpse, if not try it... http://getglimpse.com/ – Paul Zahra Aug 20 '14 at 15:18
  • @PaulZahra I use firebug but there i am not getting any data as response.. – user3924730 Aug 20 '14 at 15:19
  • 1
    json = json + "\"cell\":[" + Convert.ToString(rs["CallCost"]) + ""; is not correct... you are missing a backslash at the end. – Paul Zahra Aug 20 '14 at 15:28
  • Failing that try creating a C# object for your data, populate it, then call the javascriptserialiser so it's serialised correctly... see http://stackoverflow.com/questions/18244696/how-to-return-json-with-asp-net-jquery – Paul Zahra Aug 20 '14 at 15:29
  • @user3924730: Sorry, but you should never write the code which uses manual JSON serialization. You can use `JsonConvert.SerializeObject` from [Newtonsoft.Json](http://james.newtonking.com/json) (see [here](https://www.nuget.org/packages/newtonsoft.json/) too) or just use [JavaScriptSerializer](http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer(v=vs.90).aspx). Moreover you can use Developer Tools of IE or [Fiddler](http://www.telerik.com/fiddler) to catch HTTP trafic and append your question with **real JSON data** returned from the server. – Oleg Aug 20 '14 at 15:40
  • 1
    @user3924730: I would recommend you additionally to include [loadError](http://stackoverflow.com/a/6969114/315935) callback to your code to see **which error** will be detected on the client side if the problem is with loading of the server response. – Oleg Aug 20 '14 at 15:42

0 Answers0