public ActionResult DataSource(Syncfusion.JavaScript.DataManager dm)
{
using (SqlConnection cn = new SqlConnection(connectionStr))
{
cn.Open();
//Getting the records based on skip and top value.
SqlCommand cmd = new SqlCommand("SELECT OrderID,CustomerID,EmployeeID,Freight,OrderDate FROM Orders", cn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
dt = (DataTable)ds.Tables[0];
. . . . .
}
var order = (from DataRow row in dt.Rows
select new Order
{
OrderID = Convert.ToInt32(row["OrderID"]),
CustomerID = row["CustomerID"].ToString(),
Freight = Convert.ToDecimal(row["Freight"]),
EmployeeID = Convert.ToInt32(row["EmployeeID"]),
OrderDate = Convert.ToDateTime(row["OrderDate"])
}).Skip(dm.Skip).Take(dm.Take).ToList();
return Json(new { result = order, count = count }, JsonRequestBehavior.AllowGet);
} |
public ActionResult DataSource(Syncfusion.JavaScript.DataManager dm)
{
int count = 0;
DataSet ds = new DataSet();
DataTable dt = new DataTable();
string JSONString = null;
string connectionStr = System.Configuration.ConfigurationManager.ConnectionStrings["NORTHWNDConnectionString"].ToString();
using (SqlConnection cn = new SqlConnection(connectionStr))
{
cn.Open();
. . . .
}
var order = ToDynamicList(dt);
order = order.Skip(dm.Skip).Take(dm.Take).ToList();
return Json(new { result = order, count = count }, JsonRequestBehavior.AllowGet); //result - records, count-total records from database
}
public List<dynamic> ToDynamicList(DataTable dt)
{
List<string> cols = (dt.Columns.Cast<DataColumn>()).Select(column => column.ColumnName).ToList();
var dictData = ToDictionary(dt);
return ToDynamicList(dictData, getNewObject(cols, dictData));
}
public List<dynamic> ToDynamicList(List<Dictionary<string, object>> list, Type TypeObj)
{
dynamic temp = new List<dynamic>();
foreach (Dictionary<string, object> step in list)
{
object Obj = Activator.CreateInstance(TypeObj);
PropertyInfo[] properties = Obj.GetType().GetProperties();
Dictionary<string, object> DictList = (Dictionary<string, object>)step;
foreach (KeyValuePair<string, object> keyValuePair in DictList)
{
foreach (PropertyInfo property in properties)
{
if (property.Name == keyValuePair.Key)
{
property.SetValue(Obj, keyValuePair.Value, null);
break;
}
}
}
temp.Add(Obj);
}
return temp;
}
. . . .
} |
<input type="button" id="btn1">
<ej:Grid ID="Grid" ClientIDMode="Static" runat="server" AllowPaging="True">
<Columns>
<ej:Column Field="SrNo" TextAlign="Left"></ej:Column>
. .
</Columns>
</ej:Grid>
<script type="text/javascript">
$("#btn1").ejButton({
text: "click",
click: function (args) {
$.ajax({
type: "POST",
url: "Default.aspx/LoadStockTransfer",
. .
success: function (response) {
var gridObj = $("#Grid").ejGrid("instance");
gridObj.dataSource(response.d.objEmptyTable)
}
});
}
})
</script>
[System.Web.Services.WebMethod]
public static object LoadStockTransfer()
{
List<EmptyTable> objEmptyTable = new List<EmptyTable>();
EmptyTable obj1 = new EmptyTable();
obj1.SrNo = 1;
. . .
objEmptyTable.Add(obj1);
. .
return new { objEmptyTable };
} |