We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

I have problem with getting id row in grid AND refresh GRID without refresh browser

Thread ID:





129859 Apr 6,2017 09:14 AM UTC Apr 7,2017 12:51 PM UTC ASP.NET Core 1
Tags: Grid
Asked On April 6, 2017 09:14 AM UTC


I have problem with getting id row AND refresh GRID without refresh browser

Ofter saving(Insert Data to sql database) it needs get id( key "IsPrimaryKey and IsIdentity ") of  inserted row   or  refresh data in grid after inserting without browser refresh   

@{Html.EJ().Grid<Object>("FlatGrid") .Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.data).UpdateURL("/TestTablesControllerView/CellEditUpdate").InsertURL("/TestTablesControllerView/CellEditInsert")

.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); })
  .ToolbarSettings(toolbar =>
  toolbar.ShowToolbar().ToolbarItems(items =>
 .Columns(col =>
col.Field("Tkey").HeaderText("TKey").IsPrimaryKey(true).IsIdentity (true).Add();
 col.Field("Tid").HeaderText("Tid"   ).Add();



the set available code for get id after insert has technical problem :  "  value.Value.OrderID =order.LastOrDefault().OrderID + 1;"

I'm waiting for your prompt reply

thanks and regards.

Venkatesh Ayothi Raman [Syncfusion]
Replied On April 7, 2017 12:51 PM UTC

Hi Hassan, 
Thanks for contacting Syncfusion support. 
Query #1: “Get the row ID while inserting the record” 
We went through your code example and found that you are using isIdentity property in Grid. If we enable the Isidentity property for Auto increment column then we must handle that Auto increment column.  
So, we are the responsibility to handle the Isidentity property. While performing CRUD operation in Grid with IsIdentity column, we need to return the modified value, because of we have handled IsPrimary key column value in server side. So, we suggest you to return the modified value while performing the CRUD operation in Grid like as follows, 
Code example
public ActionResult Insert([FromBody]OrdersView value) 
            value.OrderID = ++count; //Auto increment the value for isIdnetity property 
            return Json(value, JsonRequestBehavior.AllowGet); 

Another way
You may also set the isIdentity field value while saving the record in actionBegin event like as follows, 
Code example
                            .Datasource(ds => ds.URL(@Url.Action("DataSource")).UpdateURL("/Home/CellEditUpdate") 
                      .InsertURL("/Home/CellEditInsert").RemoveURL("/Home/CellEditDelete").Adaptor(AdaptorType. RemoteSaveAdaptor)) 
                           .Columns(col => 
                               col.Field("OrderID").IsPrimaryKey(true) .IsIdentity(true).TextAlign(TextAlign.Right).Width(90).Add(); 
                               . . . 
@ActionBegin event 
<script type="text/javascript"> 
var flag=false, count=100;  
    function actionBegin(args) {         
        if (args.requestType == "add") 
            flag = true; 
        //Set the isIdentity value while inserting the record 
        if (flag && args.requestType == "save") { 
            args.data.OrderID = count++;// here OrderID is the isIdentity field and set the value while inserting the record 
            flag = false; 

Query #2: “Refresh the Grid without refresh the browser” 
We can refresh the Grid by calling the refreshContent method in Grid. Here we can refresh the Grid using button click. Please refer to the below code example and Help document, 
Code example
<input type="button" value="Grid Refresh" id="refresh"/> 
                            .Datasource(ds => ds.URL(@Url.Action("DataSource")).UpdateURL("/Home/CellEditUpdate")                      .InsertURL("/Home/CellEditInsert").RemoveURL("/Home/CellEditDelete").Adaptor(AdaptorType. RemoteSaveAdaptor)) 
                           .Columns(col => 
                               . . .   
//Refresh the Grid using button click 
        click: function () { 
            var gridObj = $("#Grid").ejGrid("instance"); 
            gridObj.refreshContent(); //Refresh the Grid by calling the refreshContent method 

Venkatesh Ayothiraman. 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon