|
[GridFeatures.aspx]
<script type="text/javascript">
var orderData = JSON.parse('<%= new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(this.gridDataSource)%>');
$("#Grid1").ejGrid({
dataSource: ej.DataManager({
json: orderData, // at initially local data binding
updateUrl: "Grid/Update", // for updating the editing values to db.
insertUrl: "Grid/Insert",
removeUrl: "Grid/Remove",
adaptor: new ej.remoteSaveAdaptor()//enable remoteSaveAdaptor
}),
---
columns: [
{ field: "OrderID", isPrimaryKey: true, headerText: "Order ID", textAlign: ej.TextAlign.Right, validationRules: { required: true, number: true }, width: 90 },
----
]
});
</script>
---------------------------------------------------------
[GridFeatures.aspx.cs]
public IEnumerable gridDataSource;
protected void Page_Load(object sender, EventArgs e)
{
BindDataSource();
}
private void BindDataSource()
{
int orderId = 10000;
int empId = 0;
for (int i = 1; i < 9; i++)
{
order.Add(new Orders(orderId + 1, "VINET", empId + 1, 32.38, new DateTime(2014, 12, 25), "Reims"));
---
}
this.gridDataSource = order;
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static object Update(Orders value)
{
var record = order.Where(o => o.OrderID == value.OrderID).FirstOrDefault();
if (record != null)
{
record.OrderID = value.OrderID;
record.CustomerID = value.CustomerID;
record.EmployeeID = value.EmployeeID;
record.Freight = value.Freight;
record.ShipCity = value.ShipCity;
}
return value;
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static object Insert(Orders value)
{
order.Insert(0,value);
return value;
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static void Remove(int key)
{
var record = order.Where(o => o.OrderID == key).FirstOrDefault();
order.Remove(record);
}
|