Search results

Get specific row and cell index in Grid in ASP.NET Core Grid control

14 Apr 2021 / 1 minute to read

You can get the specific row and cell index of the grid by using rowSelected event of the grid. Here, we can get the row and cell index by using aria-rowindex(get row Index from tr element) and aria-colindex(column index from td element) attribute.

Copied to clipboard
<ejs-grid id="Grid" dataSource="@ViewBag.DataSource" rowSelected="rowSelected">
        <e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="100"></e-grid-column>
        <e-grid-column field="CustomerID" headerText="Customer ID" type="string" width="120"></e-grid-column>
        <e-grid-column field="Freight" headerText="Freight" textAlign="Right" format="C2" editType="numericedit" width="120"></e-grid-column>
        <e-grid-column field="ShipCountry" headerText="Ship Country" width="150" editType='dropdownedit'></e-grid-column>

    function rowSelected(args) {
        alert("row index: " + args.row.getAttribute('aria-rowindex'));
        alert("column index: " +'aria-colindex'));
Copied to clipboard
public IActionResult Index()
    ViewBag.DataSource = OrderDetails.GetAllRecords();
    return View();