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

How to add primaryKey after column rendered in ASP.NET MVC Grid

We have a dynamic data grid.  We will never know exactly the fields so we can not define the columns at the start.  Though we know a column that is the primary key.  I have been binding on Action Begin, and able to edit one line on the grid (second in my test).  When I get back to the screen and try to edit another row (The first row in my test) once I click on the field to edit.  The row becomes the one I just edited and not the row I clicked on.  I am using straight razor pages with the page model.

1 Reply

DR Dhivya Rajendran Syncfusion Team July 2, 2018 04:12 AM

Hi Sybil, 
Thanks for contacting Syncfusion support. 
We have validated your query and you can resolve the reported problem by using the below way. In the below code example we have dynamically enabled isPrimaryKey property for columns in dataBound event of Grid. 
Kindly refer to the below code example more information. 
   @Html.EJS().Grid("FilterMenu").DataSource((IEnumerable<object>)ViewBag.dataSource).DataBound("dataBound").Columns(col => 
    col.Field("OrderID").HeaderText("Order ID").Add(); 
    col.Field("ShipName").HeaderText("Ship Name").Add(); 
    }).EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Normal); }).Toolbar(new List<string>() { "Add""Edit""Delete""Update""Cancel" }).Render() 
    var flag = true; 
    function dataBound() { 
        if (flag) { 
            this.getColumnByField('OrderID').isPrimaryKey = true; // dynamically enable primary key for OrderID column 
            flag = false; 

Live Chat Icon For mobile
Up arrow icon