I am unable to understand what is the error.
why my output screen is blank??
please can anyone help!!!!
I have provided the aspx and cs.
stucked at this problem from hours...
Sql database connection to jqgrid
What I have tried:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width,initial-scale=1"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/themes/redmond/jquery-ui.min.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.15.5/css/ui.jqgrid.min.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.15.5/jquery.jqgrid.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
source = {
datatype: "xml",
datafields: [
{ name: 'Emp_Code'},
{ name: 'Mgr_Code'},
{ name: 'Name'},
{ name: 'Designation'},
{ name: 'Login'},
{ name: 'Password'},
{ name: 'Zone_Code'}
],
async: false,
record: 'Table',
url: 'Default2.aspx/GetCustomers'
};
var dataAdapter = new $.jqx.dataAdapter(source,
{ contentType: 'application/json; charset=utf-8'}
);
$("#jqxgrid").jqxGrid({
source: dataAdapter,
theme: 'classic',
columns: [
{ text: 'Emp_Code', dataField: 'Emp_Code', width: 250 },
{ text: 'Mgr_Code', dataField: 'Mgr_Code', width: 150 },
{ text: 'Name', dataField: 'Name', width: 180 },
{ text: 'Designation', dataField: 'Designation', width: 180},
{ text: 'Login', dataField: 'Login', width: 80 },
{ text: 'Password', dataField: 'Password', width: 100},
{ text: 'Zone_Code', dataField: 'Zone_Code', width: 100}
]
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table id="jqxgrid"></table>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Web.Script.Services;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Script.Serialization;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetCustomers();
}
}
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Xml)]
public static string GetCustomers()
{
string query = "SELECT * From Employee_Master ";
SqlCommand cmd = new SqlCommand(query);
DataSet data = GetData(cmd);
System.IO.StringWriter writer = new System.IO.StringWriter();
data.Tables[0].WriteXml(writer, XmlWriteMode.WriteSchema, false);
return writer.ToString();
}
private static DataSet GetData(SqlCommand cmd)
{
string strConnString = ConfigurationManager.ConnectionStrings["sqlcon"].ConnectionString;
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
sda.Fill(ds);
return ds;
}
}
}
}
}