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. Image for the cookie policy date

determine the id of the selected row

Hello syncfusion support ,

Im trying to update and delete my record in grid using this code 


                    dataSource: ej.DataManager({
                        json: e.result,
                        adaptor: new ej.remoteSaveAdaptor(),
                        insertUrl: "http://localhost:11055/api/user/PostUser",
                        updateUrl: "http://localhost:11055/api/user/UpdateUser/2",  
                        removeUrl: "http://localhost:11055/api/user/DeleteRole/2",
 my question is how to know the id of the selected record to update or delete, instead of typing it manually to send it to the api

thanks in advanced

3 Replies

PK Padmavathy Kamalanathan Syncfusion Team August 1, 2019 01:59 PM UTC

Hi Ali, 

Thanks for contacting Syncfusion Support. 

QUERY: how to know the id of the selected record to update or delete, instead of typing it manually to send it to the api 
From your query we understand that you are trying to update and delete record using RemoteSaveAdaptor. For edit/delete/insert record, there is no need to manually send any id to the api.  

Please refer the below code snippet, 

In view 
<div id="Grid"> 
    <script > 
        var gridData = @Html.Raw(Json.Encode(@ViewBag.dataSource)); 
        $(function () { 
                dataSource: ej.DataManager({ 
                    json: gridData, 
                    insertUrl: "NormalInsert", 
                    updateUrl: "NormalUpdate", 
                    removeUrl: "NormalDelete", 
                    adaptor: "remoteSaveAdaptor", 
                allowPaging: true, 
                editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true }, 
                toolbarSettings: { showToolbar: true, toolbarItems: [ej.Grid.ToolBarItems.Add, ej.Grid.ToolBarItems.Edit, ej.Grid.ToolBarItems.Delete, ej.Grid.ToolBarItems.Update, ej.Grid.ToolBarItems.Cancel] }, 
                columns: [ 
                       { field: "OrderID", headerText: "Order ID", isPrimaryKey: true, width: 75, textAlign: ej.TextAlign.Right }, 
                        { field: "CustomerID", headerText: "Customer ID", width: 90 }, 
In controller 

    public class GridController : Controller 
        public static List<OrderDetails> order = new List<OrderDetails>(); 
        public ActionResult GridFeatures() 
            if (order.Count() == 0) 
            ViewBag.datasource = order; 
            return View(); 
        public ActionResult NormalUpdate(CRUDModel<OrderDetails> myObject) // method to update edited record 
            var ord = myObject.Value; 
            OrderDetails val = order.Where(or => or.OrderID == ord.OrderID).FirstOrDefault(); 
            val.OrderID = ord.OrderID; 
            val.CustomerID = ord.CustomerID; 
            return Json(myObject.Value); 
        public ActionResult NormalInsert(OrderDetails value) //method to insert new record 
            order.Insert(order.Count, value); 
            return Json(order); 
        public ActionResult NormalDelete(CRUDModel<OrderDetails> value) //method to delete record 
            order.Remove(order.Where(or => or.OrderID == int.Parse(value.Key.ToString())).FirstOrDefault()); 
            return Json(value); 

Please refer the below sample, 

Still facing the issue, please share us the below details, 
  1. Your controller and view page code
  2. Screenshot of error(if any)
  3. Explain us what do mean by id of record (primary key or index or something else?

If you have further queries, please get back to us. 

Padmavathy Kamalanathan 

AO Ali Ossaily August 2, 2019 06:55 AM UTC

Dear Padmavathy Kamalanathan , 

thanks a lot , that's exactly what I'm looking for , it works .

Best Regards.

PK Padmavathy Kamalanathan Syncfusion Team August 5, 2019 12:29 PM UTC

Hi Ali, 

We are happy to hear that your issue has been resolved. 

Feel free to get back to us if you need further assistance. 

Padmavathy Kamalanathan 

Live Chat Icon For mobile
Up arrow icon