Hi implemented jquery grid using json and dictionaries.
I am getting error with Request.InputStream. i am always getting null value.
If i pass static inputs method "GetData" it showing empty grid.
public class EmpDetails
{
public int id;
public string[] cell;
}
public class JsonEmployeeData
{
public int page;
public int total;
public int records;
public EmpDetails[] rows;
}
public partial class NewImpUsingJson : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["method"] == "GetData")
{
Request.InputStream.Position = 0;
StreamReader ipStRdr = new StreamReader(Request.InputStream);
string json = ipStRdr.ReadToEnd();
JavaScriptSerializer jser = new JavaScriptSerializer();
Dictionary<string, string> dict = jser.Deserialize<Dictionary<string, string>>(json);
NewImpUsingJson.GetData(int.Parse(dict["page"].ToString()), int.Parse(dict["rows"].ToString()), int.Parse(dict["_search"].ToString()), dict["sord"].ToString());
Response.End();
}
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static JsonEmployeeData GetData(int page, int rows, int _search, string sord)
{
string queryString = "SELECT Row_Number() over (order by EmployeeId ASC) as rowID, EmployeeId,EmployeeName,ContactNumber FROM (Select ROW_NUMBER() OVER (ORDER BY EmployeeId ASC) AS ROWID," +
"EmployeeId,EmployeeName,ContactNumber FROM EmployeeJtable) AS a"; SqlConnection connection = new SqlConnection(@"Data Source=HYD-NPULIVARTHY;Initial Catalog=test2;Integrated Security=True");
connection.Open();
DataTable dt = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter(queryString, connection);
var tRows = adapter.Fill(dt);
JsonEmployeeData result = new JsonEmployeeData();
List<EmpDetails> rowsadded = new List<EmpDetails>();
int index=1;
foreach (DataRow dtRow in dt.Rows)
{
EmpDetails newrow = new EmpDetails();
newrow.id = index++;
newrow.cell = new string[3];
newrow.cell[0] = dtRow[1].ToString();
newrow.cell[1] = dtRow[2].ToString();
newrow.cell[2] = dtRow[3].ToString();
rowsadded.Add(newrow);
}
result.rows = rowsadded.ToArray();
result.page = page;
result.total = ((rowsadded.Count + rows - 1) / tRows);
result.records = rowsadded.Count;
return result;
}
}
and my script code is
<script type="text/javascript">
$(document).ready(function () {
var sPage="NewImpUsingJson.aspx"
jQuery("#Grid1").jqGrid({
url: sPage + '?method=GetData',
datatype: 'json',
mtype: 'GET',
colNames: ['id','EmployeeId', 'EmployeeName', 'ContactNumber'],
colModel: [
{ name: 'id', index: 'id', width: 60, search: false },
{ name: 'EmployeeId', index: 'EmployeeId', width: 90, align: 'center', sorttype: 'EmployeeId'},
{ name: 'EmployeeName', index: 'EmployeeName', width: 105, align: 'right' },
{ name: 'ContactNumber', index: 'ContactNumber', width: 95, align: 'left' }
],
pager: '#pager',
sortname: 'EmployeeId',
viewrecoreds: true,
serializeGridData: function(data)
{
return JSON.stringify(data);
},
jsonReader: { repeatitems: false, root: "rows", page: "page", total: "total", records: "records" }
});
jQuery("#Grid1").jqGrid('navGrid', '#Pager', { edit: false, add: false, del: false }, null, null, true, { multipleSearch: true });
var height = $(window).height();
});
</script>
please any one help to implement displaying data in JQGrid using SQL Server 2008 data.