Click here to Skip to main content
15,887,327 members
Home / Discussions / Web Development
   

Web Development

 
GeneralRe: Website copyright India Pin
Richard MacCutchan19-Feb-15 1:43
mveRichard MacCutchan19-Feb-15 1:43 
GeneralRe: Website copyright India Pin
F-ES Sitecore19-Feb-15 1:55
professionalF-ES Sitecore19-Feb-15 1:55 
GeneralRe: Website copyright India Pin
Richard MacCutchan19-Feb-15 3:24
mveRichard MacCutchan19-Feb-15 3:24 
SuggestionRe: Website copyright India Pin
F-ES Sitecore19-Feb-15 3:37
professionalF-ES Sitecore19-Feb-15 3:37 
AnswerRe: Website copyright India Pin
manchanx8-Mar-15 14:21
professionalmanchanx8-Mar-15 14:21 
QuestionASP Sitemap Pin
Darrylw9915-Feb-15 6:24
Darrylw9915-Feb-15 6:24 
AnswerRe: ASP Sitemap Pin
Lord_Nick6927-Mar-15 7:26
Lord_Nick6927-Mar-15 7:26 
QuestionUnable to bind JQGrid with the json data using html and httphandler Pin
Karthik@201210-Feb-15 18:37
Karthik@201210-Feb-15 18:37 
Following is the code for jqgrid -
html page-

XML
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

XML
<script src="Scripts/JQGridReq/jquery-1.9.0.min.js"></script>
    <link href="Scripts/JQGridReq/jquery-ui-1.9.2.custom.css" rel="stylesheet" />
    <script src="Scripts/JQGridReq/jquery.jqGrid.js"></script>
    <link href="Scripts/JQGridReq/ui.jqgrid.css" rel="stylesheet" />
    <script src="Scripts/JQGridReq/grid.locale-en.js"></script>

<title>








jQuery("#jqGrid").jqGrid({
url: 'Handler1.ashx',
datatype: "json",
colNames: ['S_Course_Name', 'S_Course_Desc'],
colModel: [
{ name: 'S_Course_Name', index: 'S_Course_Name', width: 50, stype: 'text', editable: true },
{ name: 'S_Course_Desc', index: 'S_Course_Desc', width: 80, stype: 'text', sortable: true, editable: true }

],
rowNum: 10,
mtype: 'GET',
loadonce: true,
rowList: [10, 20, 30],
pager: '#Pager',
sortname: 'S_Course_Name',
viewrecords: true,
sortorder: 'desc',
caption: "Course Detail",
width: 500,
editurl: 'Handler1.ashx'
});

$('#jqGrid').jqGrid('navGrid', '#Pager',
{
edit: true,
add: false,
del: true,
search: true,
searchtext: "Search",
addtext: "Add",
edittext: "Edit",
deltext: "Delete"
},
{ //EDIT
// height: 300,
// width: 400,
// top: 50,
// left: 100,
// dataheight: 280,
closeOnEscape: true, //Closes the popup on pressing escape key
reloadAfterSubmit: true,
drag: true,
afterSubmit: function (response, postdata) {
if (response.responseText == "") {

$(this).jqGrid('setGridParam', { datatype: 'json' }).trigger('reloadGrid'); //Reloads the grid after edit
return [true, '']
}
else {
$(this).jqGrid('setGridParam', { datatype: 'json' }).trigger('reloadGrid'); //Reloads the grid after edit
return [false, response.responseText]//Captures and displays the response text on th Edit window
}
},
editData: {
EmpId: function () {
var sel_id = $('#jqGrid').jqGrid('getGridParam', 'selrow');
var value = $('#jqGrid').jqGrid('getCell', sel_id, 'S_Course_Name');
return value;
}
}
},
{
closeAfterAdd: true, //Closes the add window after add
afterSubmit: function (response, postdata) {
if (response.responseText == "") {

$(this).jqGrid('setGridParam', { datatype: 'json' }).trigger('reloadGrid')//Reloads the grid after Add
return [true, '']
}
else {
$(this).jqGrid('setGridParam', { datatype: 'json' }).trigger('reloadGrid')//Reloads the grid after Add
return [false, response.responseText]
}
}
},
{ //DELETE
closeOnEscape: true,
closeAfterDelete: true,
reloadAfterSubmit: true,
closeOnEscape: true,
drag: true,
afterSubmit: function (response, postdata) {
if (response.responseText == "") {

$("#jqGrid").trigger("reloadGrid", [{ current: true }]);
return [false, response.responseText]
}
else {
$(this).jqGrid('setGridParam', { datatype: 'json' }).trigger('reloadGrid');
return [true, response.responseText]
}
},
delData: {
EmpId: function () {
var sel_id = $('#jqGrid').jqGrid('getGridParam', 'selrow');
var value = $('#jqGrid').jqGrid('getCell', sel_id, 'S_Course_Name');
return value;
}
}
},
{//SEARCH
closeOnEscape: true

}
);







Handler1.ashx.cs-

public class Handler1 : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{

context.Response.ContentType = "application/json";
System.Collections.Specialized.NameValueCollection forms = context.Request.Form;
string strOperation = forms.Get("oper");

string strResponse = string.Empty;

if (strOperation == null)
{

DataTable dt = getCourseDetail();
var jsonSerializer = new JavaScriptSerializer();
context.Response.Write(jsonSerializer.Serialize(GetCourseDetailListFromDataTable(dt)));

}
else if (strOperation == "del")
{
//var query = Query.EQ("_id", forms.Get("EmpId").ToString());
//collectionEmployee.Remove(query);
//strResponse = "Employee record successfully removed";
//context.Response.Write(strResponse);
}
else
{
//string strOut = string.Empty;
//AddEdit(forms, collectionEmployee, out strOut);
//context.Response.Write(strOut);
}
}

public bool IsReusable
{
get
{
return false;
}
}

public static DataTable getCourseDetail()
{
string strConnection = System.Configuration.ConfigurationManager.ConnectionStrings["connectionstring"].ToString();
using (SqlConnection con = new SqlConnection(strConnection))
{
con.Open();
SqlCommand sqlcomm = new SqlCommand("SELECT TOP 5 S_Course_Name,S_Course_Desc FROM T_Course_Master", con);
//SqlCommand sqlcomm = new SqlCommand("SELECT TOP 10 I_Course_ID,I_CourseFamily_ID,S_Course_Code,S_Course_Name,S_Course_Desc FROM T_Course_Master", con);
SqlDataAdapter da = new SqlDataAdapter(sqlcomm);
DataTable table = new DataTable();

da.Fill(table);
//string data = GetJson(table);
//return data;
return table;
}

}

public static string GetJson(DataTable dt)
{
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
List> rows = new List>();
Dictionary row;
foreach (DataRow dr in dt.Rows)
{
row = new Dictionary();
foreach (DataColumn col in dt.Columns)
{
row.Add(col.ColumnName, dr[col]);
}
rows.Add(row);
}

return serializer.Serialize(rows);
}

private List GetCourseDetailListFromDataTable(DataTable dt)
{

//List type object of the property class
List courseDetailClass = new List();
foreach (DataRow dr in dt.Rows)
{
//Object of the propery class
CourseDetail objCourseDetail = new CourseDetail();
//asign values
objCourseDetail.S_Course_Name = dr["S_Course_Name"].ToString();
objCourseDetail.S_Course_Desc = dr["S_Course_Desc"].ToString();

//add one row to the list
courseDetailClass.Add(objCourseDetail);
}
//return final list
return courseDetailClass;
}

method is getting called but data is not displayed in the grid.I m getting the json string also proper format. kindly some help on this.
SuggestionRe: Unable to bind JQGrid with the json data using html and httphandler Pin
Richard MacCutchan10-Feb-15 22:16
mveRichard MacCutchan10-Feb-15 22:16 
QuestionREST API User Authentication Pin
IsoftTech10-Feb-15 8:37
IsoftTech10-Feb-15 8:37 
AnswerRe: REST API User Authentication Pin
Afzaal Ahmad Zeeshan13-Feb-15 1:24
professionalAfzaal Ahmad Zeeshan13-Feb-15 1:24 
Questionusing OUT in PDO and PHP Pin
Jassim Rahma9-Feb-15 1:20
Jassim Rahma9-Feb-15 1:20 
QuestionRe: using OUT in PDO and PHP Pin
ZurdoDev9-Feb-15 5:05
professionalZurdoDev9-Feb-15 5:05 
QuestionAdd payment option Pin
Super Lloyd6-Feb-15 18:26
Super Lloyd6-Feb-15 18:26 
AnswerRe: Add payment option Pin
Afzaal Ahmad Zeeshan6-Feb-15 20:38
professionalAfzaal Ahmad Zeeshan6-Feb-15 20:38 
GeneralRe: Add payment option Pin
Super Lloyd6-Feb-15 22:15
Super Lloyd6-Feb-15 22:15 
AnswerRe: Add payment option Pin
Afzaal Ahmad Zeeshan6-Feb-15 23:38
professionalAfzaal Ahmad Zeeshan6-Feb-15 23:38 
GeneralRe: Add payment option Pin
Super Lloyd7-Feb-15 0:05
Super Lloyd7-Feb-15 0:05 
GeneralRe: Add payment option Pin
Afzaal Ahmad Zeeshan7-Feb-15 0:09
professionalAfzaal Ahmad Zeeshan7-Feb-15 0:09 
SuggestionRe: Add payment option Pin
Richard Deeming9-Feb-15 3:08
mveRichard Deeming9-Feb-15 3:08 
GeneralRe: Add payment option Pin
Super Lloyd9-Feb-15 10:43
Super Lloyd9-Feb-15 10:43 
Questionwhy (Cannot send session)?! Pin
Jassim Rahma3-Feb-15 21:09
Jassim Rahma3-Feb-15 21:09 
QuestionBorderline programing question sorry.. :'( Pin
Super Lloyd29-Jan-15 3:20
Super Lloyd29-Jan-15 3:20 
AnswerRe: Borderline programing question sorry.. :'( Pin
Richard Deeming29-Jan-15 8:08
mveRichard Deeming29-Jan-15 8:08 
GeneralRe: Borderline programing question sorry.. :'( Pin
Super Lloyd29-Jan-15 12:48
Super Lloyd29-Jan-15 12:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.