Forum


13:01

01/06/2009

Hello Everybody,
jqGrid is really really good. I've made demos using asp.net and webservice (asmx) and handler (ashx). But my question is, can I call methods from c# code behind? I've an idea of using it in my project. We cannot use WebService in our current project, that is the reason I need to use in c# code behind.
<script type="text/javascript">
jQuery(document).ready(function() {
var data = "{}";
var jsonStr = JSON.stringify(data);
var lastSel;
$('#list').jqGrid({
datatype: function() {
$.ajax({
url: "jqGridDemo.asmx/NewMethod",
data: "{}", // For empty input data use "{}",
dataType: "json",
mtype: "GET",
contentType: "application/json; charset=utf-8",
complete: function(jsondata, stat) { alert((jsondata.responseText));
if (stat == "success") {
var thegrid = jQuery("#list")[0];
thegrid.addJSONData(JSON.parse(jsondata.responseText).d);
}
}
});
},
colNames: ['User ID', 'User Name', 'Location'],
colModel: [
{ name: 'ID', index: 'ID', width: 80, align: 'left', editable: false },
{ name: 'Name', index: 'Name', width: 120, align: 'left', editable: true},
{ name: 'Location', index: 'Location', width: 60, align: 'left', editable: true, edittype: "select", editoptions: { value: "MDU:Madurai; BAN:Bangalore; CHE:Chennai"}}],
pager: jQuery('#pager'),
rowNum: 5,
rowList: [10, 20, 30],
sortname: 'ID',
sortorder:'desc',
viewrecords: true,
imgpath: 'jqGrid-3.4.3/themes/coffee/images',
caption: 'jqGrid First Grid',
width: 300,
editurl: "operation.ashx"
}).navGrid(pager, { edit: true, add: true, del: true, search: false });
});
</script>
In the above code, the highlighted code is used to call the "NewMethod" from WebService. Instead of jqGridDemo.asmx, how can I call the c# code behind's method? If anyone have any idea, please let me know.
Thanks,
achu
14:52

public static object LoadCustomerLevels(GridObject Params)
{
sysUsers.IsUsersSessionTimeOut();
sysUsers.IsRead(KitapEnumTableObject.tblSeviye);
var qSeviye = SaglayiciSeviye.Tumu().SortEngine(Params.sidx,(Params.sord=="asc"),false).ToList();
var qReturn = new
{
page = Params.page,
total = (qSeviye.Count / Params.rows),
records = qSeviye.Count,
rows = qSeviye.Select(pk => new
{
id = pk.SeviyeID,
cell = new object[] {
pk.Seviye_Metin,
""
}
}).ToList()
};
return qReturn;
}
17:18

25/02/2009

Hi Engineer,
I use a custom datatype to call webmethods from codebehind like so:
$.ajax({ type: "POST",
url: 'ViewEmployees.aspx/GetEmployees',
contentType: "application/json; charset=utf-8",
data: "{'colname': '" + $("#list4").getGridParam('sortname') + "', 'order' : '" + $("#list4").getGridParam('sortorder') + "'}",
dataType: "xml",
error: handleJqAjaxError,
complete: function(jsondata, stat) {
if (stat == "success") {
var thegrid = jQuery("#list4")[0];
thegrid.addXmlData(jsondata.responseXML);
}
}
});
Just make sure you decorate your codebehind methods with the webmethod attribute so asp.net allows them to be called remotely.
02:15

01/06/2009

element said:
Hi Engineer,
I use a custom datatype to call webmethods from codebehind like so:
datatype: function(pdata) {
$.ajax({ type: “POST”,
url: 'ViewEmployees.aspx/GetEmployees',
contentType: “application/json; charset=utf-8″,
data: “{'colname': '” + $(”#list4″).getGridParam('sortname') + “', 'order' : '” + $(”#list4″).getGridParam('sortorder') + “'}”,
dataType: “xml”,
error: handleJqAjaxError,
complete: function(jsondata, stat) {
if (stat == “success”) {
var thegrid = jQuery(”#list4″)[0];
thegrid.addXmlData(jsondata.responseXML);
}
}
});Just make sure you decorate your codebehind methods with the webmethod attribute so asp.net allows them to be called remotely.
I too tried like what you did, but the method was not fired. Can you show me your code-behind part? That'll be really helpful.
02:16

01/06/2009

Firro said:
public static object LoadCustomerLevels(GridObject Params)
{
sysUsers.IsUsersSessionTimeOut();
sysUsers.IsRead(KitapEnumTableObject.tblSeviye);
var qSeviye = SaglayiciSeviye.Tumu().SortEngine(Params.sidx,(Params.sord==”asc”),false).ToList();var qReturn = new
{
page = Params.page,
total = (qSeviye.Count / Params.rows),
records = qSeviye.Count,
rows = qSeviye.Select(pk => new
{
id = pk.SeviyeID,
cell = new object[] {
pk.Seviye_Metin,
“”
}
}).ToList()
};return qReturn;
}
Will it work if you don't use a Static method? More over I don't understand your method. Any explaination?
Most Users Ever Online: 715
Currently Online:
52 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66