Forum

July 10th, 2011
You must be logged in to post Login Register

Search Forums:


 






jqGrid using HttpHandler, no data displaying.

No Tags
UserPost

10:08
24/06/2012


parag.patil

New Member

posts 1

Hi All,

I am new to jqGrid. I am using free version of jqGrid (not Trirand commercial). To bind data to grid, i have created HttpHandler. It is returning data properly but still data in jqGrid is not displaying. Below is sample code.

Could anyone tell me what is wrong?

in aspx file.



<!——–Included files—————->
<link href="Themes/ui.jqgrid.css" rel="stylesheet" type="text/css" />
<link href="Themes/redmond/jquery-ui-1.8.2.custom.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-en.js" type="text/javascript"></script>

$(function () {
jQuery("#abGrid").jqGrid({
url: 'abHttpHandler.ashx',
datatype: 'json',
colNames: ['ABID', 'ABNumber', 'InvNo', 'InvDate'],
colModel: [{ name: 'ABID', index: 'ABID', width: 20, editable: false, editoptions: { readonly: true, size: 10} },
{ name: 'ABNumber', index: 'ABNumber', width: 30, editable: false, editoptions: { readonly: true, size: 30} },
{ name: 'InvNo', index: 'InvNo', width: 30, editable: false },
{ name: 'InvDate', index: 'InvDate', width: 50, editable: false }
],
rowNum: 10,
rowList: [2, 5, 10, 15, 20],
pager: '#abPager',
sortName: 'ABID',
sortOrder: 'asc',
viewRecords: true,
width: 600,
caption: 'ABGrid',
height: '100%',
editurl: 'abHttpHandler.ashx'
});

jQuery("#abGrid").navGrid("#abPager", { edit: false, add: true, del: false }, { closeAfterEdit: false, reloadAfterSubmit: false }, { closeAfterAdd: false, reloadAfterSubmit: false }, { reloadAfterSubmit: false });
});
</script>

<body>
<form id="form1″ runat="server">
<table id="abGrid">
<div id="abPager"></div>
</table>
</form>
</body>

Below is the HttpHandler Code.



using System;
using System.Web;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Web.Script.Serialization;

public class abHttpHandler : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{

HttpRequest request = context.Request;
HttpResponse response = context.Response;
AB abObject = new AB();

var jsonSerializer = new JavaScriptSerializer();
response.Write(jsonSerializer.Serialize(abObject.GetAB()));
response.End();
}

public bool IsReusable
{
get
{
return false;
}
}

[SerializableAttribute]
private class AB
{
private long _ABID;
private string _ABNumber;
private string _InvNo;
private DateTime _InvDate;

public long ABID
{
get { return _ABID; }
set { _ABID = value; }
}

public string ABNumber
{
get { return _ABNumber; }
set { _ABNumber = value; }
}

public string InvNo
{
get { return _InvNo; }
set { _InvNo = value; }
}

public DateTime InvDate
{
get { return _InvDate; }
set { _InvDate = value; }
}

public List<AB> GetAB()
{
List<AB> abCollection = new List<AB>();

SqlDataReader datareader;
SqlConnection conn;
SqlCommand cmd;

using(conn = new SqlConnection("My Connection String to Database"))
{
using(cmd = new SqlCommand("select ABID,ABNumber,InvNo,InvDate from sampleTable"))
{
cmd.Connection=conn;
conn.Open();
datareader = cmd.ExecuteReader();

while(datareader.Read())
{
AB ab = new AB();

ABID = Convert.ToInt64(datareader["ABID"]);
ABNumber=Convert.ToString(datareader["ABNumber"]);
InvNo=Convert.ToString(datareader["InvNo"]);
InvDate=Convert.ToDateTime(datareader["InvDate"]);

abCollection.Add(ab);

}
}

}
return abCollection;
}
}

No Tags

About the jQuery Grid Plugin – jqGrid forum

Most Users Ever Online:

157


Currently Online:

BaHeK83

37 Guests

Forum Stats:

Groups: 1

Forums: 7

Topics: 9592

Posts: 28785

Membership:

There are 10170 Members

There have been 448 Guests

There is 1 Admin

There are 2 Moderators

Top Posters:

OlegK – 1157

markw65 – 179

kobruleht – 144

phicarre – 126

YamilBracho – 124

Renso – 118

Administrators: admin (56 Posts)

Moderators: tony (7009 Posts), Rumen[Trirand] (81 Posts)




Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information