Search results

Select grid rows based on certain condition in ASP.NET Core Grid control

20 Jan 2022 / 1 minute to read

You can select the specific row in the grid based on a certain condition by using the selectRows method in the dataBound event of Grid.

In the below demo, we have selected the grid rows only when EmployeeID column value greater than 3.

Copied to clipboard
<div id="GridParent">
    <ejs-grid id="Grid" dataSource="@ViewBag.DataSource" height="315" allowSelection="true" allowPaging="true" dataBound="dataBound" rowDataBound="rowDataBound">
        <e-grid-selectionsettings type="Multiple"></e-grid-selectionsettings>
            <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="EmployeeID" headerText="Employee ID" textAlign="Right" width="120"></e-grid-column>
            <e-grid-column field="ShipCity" headerText="Ship City" width="120"></e-grid-column>
            <e-grid-column field="ShipCountry" headerText="Ship Country" width="150"></e-grid-column>


    var selIndex = [];

    function rowDataBound(args) {
        if (['EmployeeID'] > 3) {

    function dataBound(args) {
        if (selIndex.length) {
            selIndex = [];
Copied to clipboard
public IActionResult Index()
    var Order = OrderDetails.GetAllRecords();
    ViewBag.DataSource = Order;
    return View();