Introduction
In this article, I will explain how to create DevExpress Grid View using ASP.NET Webform and MVC API Controller.
HTML Markup
The HTML Markup has a DIV (id="gridContainer") that will hold the data coming from WebAPI, Header section has Jquery, DevExpress libraries, and the final JavaScript to read the API data and assign it to the DevExpress Grid View.
First, you need to add the below CDNs in the Header Section.
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/19.1.4/css/dx.common.css" />
- <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/19.1.4/css/dx.material.teal.light.compact.css" />
- <script src="https://cdn3.devexpress.com/jslib/19.1.4/js/dx.all.js"></script>
Create a div tag as below and assign id="gridContainer".
<div id="gridContainer"></div>
Now write the JavaScript to read the API data and assign to the dev express grid the tag "gridContainer"
- <script>
- $(document).ready(function () {
- uri2 = "/api/Customer/GetCustomers";
- dataGridContainer(uri2);
- });
- /******************Data Grid Container******************/
- function dataGridContainer(URL) {
- $("#gridContainer").dxDataGrid({
- dataSource: URL,
- columns: [
- //Enter the respective field names that is comimg from the API data
- {
- dataField: "CustomerId"
- },
- {
- dataField: "ContactName",
- caption: "Contact Name"
- },
- {
- dataField: "DepartmentName"
- },
- {
- dataField: "ProductName"
- },
- ],
- showBorders: true,
- filterRow: {
- visible: true
- },
- headerFilter: {
- visible: false
- },
- paging: {
- pageSize: 5
- },
- pager: {
- showInfo: true
- },
- height: 420,
- });
- }
- </script>
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DevExpressGrid.aspx.cs" Inherits="ASPShortCodes.DevExpressGrid" %>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title>DevExpressGrid</title>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/19.1.4/css/dx.common.css" />
- <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/19.1.4/css/dx.material.teal.light.compact.css" />
- <script src="https://cdn3.devexpress.com/jslib/19.1.4/js/dx.all.js"></script>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <div class="demo-container">
- <div id="gridContainer"></div>
- </div>
- </div>
- </form>
- <script>
- $(document).ready(function () {
- uri2 = "/api/Customer/GetCustomers";
- dataGridContainer(uri2);
- });
- /******************Data Grid Container******************/
- function dataGridContainer(URL) {
- $("#gridContainer").dxDataGrid({
- dataSource: URL,
- columns: [
- {
- dataField: "CustomerId"
- },
- {
- dataField: "ContactName",
- caption: "Contact Name"
- },
- {
- dataField: "DepartmentName"
- },
- {
- dataField: "ProductName"
- },
- ],
- showBorders: true,
- filterRow: {
- visible: true
- },
- headerFilter: {
- visible: false
- },
- paging: {
- pageSize: 5
- },
- pager: {
- showInfo: true
- },
- height: 420,
- });
- }
- </script>
- </body>
- </html>
You will need to create a Web API Controller in the same or different Application to access the Customer data.
C#
Create the Class Customer with the required fields and write a function called "GetCustomers( )" to return Customer data as a List type.
Create a Customer Class as shown below:

Join the conversation! Your thoughts help the community grow.