Please please .. provide complete sample code to populate and refresh jquery datatables
Please please .. provide complete sample code to populate and refresh jquery datatables
Please please .. provide complete sample code to populate and refresh jquery datatables in .net(NOT MVC).. i have created a web service as below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
///
/// Summary description for GetPatients
///
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class GetEmployee : System.Web.Services.WebService {
public GetEmployee () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
public class Patient
{
public string sno;
public string Employeename;
public string age;
public string city;
public string state;
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
public List GetRecipie()
{
string strQuery = "SELECT * FROM tblEmployee";
DataTable dtpatient = null;
Patient objpatient;
SqlConnection con = GetConnection(ConfigurationManager.ConnectionStrings["WebFormConnectionString"].ConnectionString);
using (con)
{
con.Open();
using (SqlDataAdapter sqlAdapter = new SqlDataAdapter(strQuery, con))
{
dtpatient = new DataTable();
sqlAdapter.Fill(dtpatient);
}
}
List drlist = new List();
foreach (DataRow row in dtEmployee.Rows)
{
objEmployee= new Employee();
objEmployee.sno = row["RegisterationNo"].ToString();
objEmployee.Employeename= row["Employeename"].ToString();
objEmployee.age = row["Age"].ToString();
objEmployee.city = row["City"].ToString();
objEmployee.state = row["State"].ToString();
drlist.Add(objEmployee);
}
return drlist;
}
private SqlConnection GetConnection(string m_conString)
{
SqlConnection con = new SqlConnection(m_conString);
return con;
}
}
and on the asp.net i do...
var table = $('#abc').dataTable({ //grid is the id of the table
"sAjaxSource": "http://localhost:11111/JWebFormDatatablesWebService/GetEmployee.asmx?op=GetRecipie",
"aoColumns": [
{ "mDataProp": "Id" },
{ "mDataProp": "Name" },
{ "mDataProp": "City" },
{ "mDataProp": "State" }],
"aaSorting": [[0, "asc"]], "sPaginationType": "full_numbers", "sScrollY": "200px"
});
and...
Id
Name
City
State
Loading....
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
///
/// Summary description for GetPatients
///
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class GetEmployee : System.Web.Services.WebService {
public GetEmployee () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
public class Patient
{
public string sno;
public string Employeename;
public string age;
public string city;
public string state;
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
public List GetRecipie()
{
string strQuery = "SELECT * FROM tblEmployee";
DataTable dtpatient = null;
Patient objpatient;
SqlConnection con = GetConnection(ConfigurationManager.ConnectionStrings["WebFormConnectionString"].ConnectionString);
using (con)
{
con.Open();
using (SqlDataAdapter sqlAdapter = new SqlDataAdapter(strQuery, con))
{
dtpatient = new DataTable();
sqlAdapter.Fill(dtpatient);
}
}
List drlist = new List();
foreach (DataRow row in dtEmployee.Rows)
{
objEmployee= new Employee();
objEmployee.sno = row["RegisterationNo"].ToString();
objEmployee.Employeename= row["Employeename"].ToString();
objEmployee.age = row["Age"].ToString();
objEmployee.city = row["City"].ToString();
objEmployee.state = row["State"].ToString();
drlist.Add(objEmployee);
}
return drlist;
}
private SqlConnection GetConnection(string m_conString)
{
SqlConnection con = new SqlConnection(m_conString);
return con;
}
}
and on the asp.net i do...
var table = $('#abc').dataTable({ //grid is the id of the table
"sAjaxSource": "http://localhost:11111/JWebFormDatatablesWebService/GetEmployee.asmx?op=GetRecipie",
"aoColumns": [
{ "mDataProp": "Id" },
{ "mDataProp": "Name" },
{ "mDataProp": "City" },
{ "mDataProp": "State" }],
"aaSorting": [[0, "asc"]], "sPaginationType": "full_numbers", "sScrollY": "200px"
});
and...
Id
Name
City
State
Loading....
This discussion has been closed.