{"id":1349,"date":"2011-09-28T13:03:13","date_gmt":"2011-09-28T09:03:13","guid":{"rendered":"http:\/\/www.dhtmlx.com\/blog\/?p=1349"},"modified":"2025-05-19T14:43:34","modified_gmt":"2025-05-19T11:43:34","slug":"how-to-use-dhtmlxgrid-with-asp-net-mvc","status":"publish","type":"post","link":"https:\/\/dhtmlx.com\/blog\/how-to-use-dhtmlxgrid-with-asp-net-mvc\/","title":{"rendered":"How to Use dhtmlxGrid with ASP.NET MVC"},"content":{"rendered":"<p>In this tutorial we are going to explain how to use <a href=\"https:\/\/dhtmlx.com\/docs\/products\/dhtmlxGrid\/\">dhtmlxGrid<\/a> with ASP.NET MVC. Following this article step by step will allow you to implement an editable datagrid with sorting and filtering capabilities. We will also describe how to bind the grid data to the database and update it on the server side when user makes changes in browser. <\/p>\n<p>We will use the Standard Edition of dhtmlxGrid, which is available under GNU GPL. As an example, we will create a table of users. Not to do the same work twice, we just use the same records that were used for our RoR implementation. The image below shows how our datagrid will look.<\/p>\n<p><a href=\"https:\/\/dhtmlx.com\/x\/download\/regular\/tutorials\/dhtmlxGrid_net_mvc.zip\">Download the final demo<\/a> and follow the tutorial to integrate dhtmlxGrid in an ASP.NET MVC application.<\/p>\n<div id=\"attachment_429\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-429\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/07\/ready_grid.gif\" alt=\"Grid with ASP.NET MVC Example\" title=\"Grid with ASP.NET MVC Example\" width=\"600\" height=\"430\" class=\"size-full wp-image-429\" srcset=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/07\/ready_grid.gif 600w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/07\/ready_grid-300x215.gif 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><p id=\"caption-attachment-429\" class=\"wp-caption-text\">Grid with ASP.NET MVC Example<\/p><\/div>\n<p><!--more--><br \/>\n&nbsp;<br \/>\n<strong>Setting the Environment<\/strong><\/p>\n<p>First we create an empty ASP.NET MVC application. We should also create a database and a table of users. There will be 3 fields for storing: First Name, Last Name, and Phone Number.  <\/p>\n<p>We need to create a folder for the database. Go to project->Add->Add ASP.Net folder and add folder App_data. In this folder we create a database with one table \u2013 <strong>Users<\/strong>:<\/p>\n<ul>\n<li>id \u2013 int, primary<\/li>\n<li>first_name &#8211; nvarchar(128)<\/li>\n<li>last_name &#8211; nvarchar(128)<\/li>\n<li>phone &#8211; nvarchar(128)<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>NOTE: You can also create a database on MS SQL Server. In this case, you will need to add connectionString in web.config manually.<\/p>\n<p>Then we&#8217;re creating a model and controller for our demo. Add <strong>\/Controllers\/AdminController.cs<\/strong>:<\/p>\n<div class=\"codecolorer-container csharp default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"csharp codecolorer\"><span class=\"kw1\">public<\/span> <span class=\"kw4\">class<\/span> AdminController <span class=\"sy0\">:<\/span> Controller<br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">public<\/span> ActionResult Index<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">return<\/span> View<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><\/div><\/div>\n<p>We also should add a new data model. Go to Models->Add->New Item->Linq to SQL classes. The name of the file will be <strong>GridUsers.dbml<\/strong>. In the visual designer we create a mapping object of the table <strong>Users<\/strong> (you can just drag-n-drop the table from ServerExplorer into the visual designer).<\/p>\n<p>Now we are ready to use dhtmlxGrid and start building the main part of our table <strong>Users<\/strong>. <\/p>\n<p>&nbsp;<br \/>\n<strong>Loading Empty Grid<\/strong><\/p>\n<p>Download the latest dhtmlxGrid Standard package. Unzip it and copy the folders dhtmlxGrid\/codebase and dhtmlxDataProcessor\/codebase to the \/Scripts\/ folder of your demo application. <\/p>\n<p>The dhtmlxGrid package includes a lot of examples and supporting materials, which are not necessary for our demo. We are taking only the files that are required to build the grid.<\/p>\n<p>After that we can add the first view &#8211; the file <strong>\/Views\/Admin\/Index.aspx<\/strong>:<\/p>\n<div class=\"codecolorer-container html4strict default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"html4strict codecolorer\"><span class=\"sc2\">&lt;%@ Page <span class=\"kw3\">Language<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;C#&quot;<\/span> Inherits<span class=\"sy0\">=<\/span><span class=\"st0\">&quot;System.Web.Mvc.ViewPage&lt;dynamic&gt;<\/span><\/span>&quot; %&gt;<br \/>\n<span class=\"sc0\">&lt;!DOCTYPE HTML PUBLIC &quot;-\/\/W3C\/\/DTD HTML 4.01 Transitional\/\/EN&quot;<\/span><br \/>\n<span class=\"sc0\">&nbsp; &nbsp; &quot;http:\/\/www.w3.org\/TR\/html4\/loose.dtd&quot;&gt;<\/span><br \/>\n<span class=\"sc2\">&lt;<span class=\"kw2\">html<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">head<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">script<\/span> <span class=\"kw3\">src<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;\/Scripts\/dhtmlxcommon.js&quot;<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/javascript&quot;<\/span> <span class=\"kw3\">charset<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span>&gt;&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">script<\/span> <span class=\"kw3\">src<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;\/Scripts\/dhtmlxgrid.js&quot;<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/javascript&quot;<\/span> <span class=\"kw3\">charset<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span>&gt;&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">script<\/span> <span class=\"kw3\">src<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;\/Scripts\/dhtmlxgridcell.js&quot;<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/javascript&quot;<\/span> <span class=\"kw3\">charset<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span>&gt;&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">link<\/span> <span class=\"kw3\">rel<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;stylesheet&quot;<\/span> <span class=\"kw3\">href<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;\/Scripts\/dhtmlxgrid.css&quot;<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/css&quot;<\/span> <span class=\"kw3\">media<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;screen&quot;<\/span> <span class=\"kw3\">charset<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">link<\/span> <span class=\"kw3\">rel<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;stylesheet&quot;<\/span> <span class=\"kw3\">href<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;\/Scripts\/skins\/dhtmlxgrid_dhx_skyblue.css&quot;<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/css&quot;<\/span> <span class=\"kw3\">media<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;screen&quot;<\/span> <span class=\"kw3\">charset<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">head<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">body<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">div<\/span> <span class=\"kw3\">id<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;grid_here&quot;<\/span> <span class=\"kw3\">style<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;width:600px; height:400px;&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">div<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">script<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/javascript&quot;<\/span> <span class=\"kw3\">charset<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var grid = new dhtmlXGridObject(&quot;grid_here&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;grid.setImagePath(&quot;\/javascripts\/codebase\/imgs\/&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;grid.setHeader(&quot;First name, Last name, Phone&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;grid.setInitWidths(&quot;100,100,*&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;grid.setSkin(&quot;dhx_skyblue&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;grid.init();<br \/>\n&nbsp; &nbsp;<br \/>\n&nbsp; &nbsp;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">body<\/span>&gt;<\/span><br \/>\n<span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">html<\/span>&gt;<\/span><\/div><\/div>\n<p>NOTE:<\/p>\n<ul>\n<li>setImagePath points to codebase\/imgs from the dhtmlxGrid package.<\/li>\n<li>setHeader defines the structure of the grid, so the client-side grid will have columns to show data from our Users table (columns First Name, Last Name, and Phone Number).<\/li>\n<li>setInitWidths command defines the widths of columns, and * as the width for the last column enables auto-size for this column.<\/li>\n<\/ul>\n<p>&nbsp;<br \/>\nAs you can see, this view doesn&#8217;t contain any active logic, it just loads .js and .css files and initializes a JavaScript grid on the page. <\/p>\n<p>In <strong>Global.asax<\/strong> we should change the default settings of request routing:<\/p>\n<div class=\"codecolorer-container csharp default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"csharp codecolorer\">\u2026<br \/>\n<span class=\"kw1\">public<\/span> <span class=\"kw1\">static<\/span> <span class=\"kw4\">void<\/span> RegisterRoutes<span class=\"br0\">&#40;<\/span>RouteCollection routes<span class=\"br0\">&#41;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n\u2026<br \/>\nroutes<span class=\"sy0\">.<\/span><span class=\"me1\">MapRoute<\/span><span class=\"br0\">&#40;<\/span><br \/>\n&nbsp; &nbsp; &nbsp;<span class=\"st0\">&quot;Default&quot;<\/span>, <span class=\"co1\">\/\/ Route name<\/span><br \/>\n&nbsp; &nbsp; &nbsp;<span class=\"st0\">&quot;{controller}\/{action}\/{id}&quot;<\/span>, <span class=\"co1\">\/\/ URL with parameters<\/span><br \/>\n&nbsp; &nbsp; &nbsp;<span class=\"kw3\">new<\/span> <span class=\"br0\">&#123;<\/span> controller <span class=\"sy0\">=<\/span> <span class=\"st0\">&quot;Admin&quot;<\/span>, action <span class=\"sy0\">=<\/span> <span class=\"st0\">&quot;Index&quot;<\/span>, id <span class=\"sy0\">=<\/span> UrlParameter<span class=\"sy0\">.<\/span><span class=\"me1\">Optional<\/span> <span class=\"br0\">&#125;<\/span> <span class=\"co1\">\/\/ Parameter defaults<\/span><br \/>\n<span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n\u2026<br \/>\n<span class=\"br0\">&#125;<\/span><br \/>\n\u2026<\/div><\/div>\n<p>Now, if you run your demo application, you will see an empty grid with 3 columns. This will be the structure of our table of users:<\/p>\n<div id=\"attachment_428\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-428\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/07\/grid_empty.gif\" alt=\"Grid with ASP.NET MVC - Empty Grid\" title=\"Grid with ASP.NET MVC - Empty Grid\" width=\"600\" height=\"404\" class=\"size-full wp-image-428\" srcset=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/07\/grid_empty.gif 600w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/07\/grid_empty-300x202.gif 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><p id=\"caption-attachment-428\" class=\"wp-caption-text\">Grid with ASP.NET MVC - Empty Grid<\/p><\/div>\n<p>&nbsp;<br \/>\n<strong>Filling Grid with Data<\/strong><\/p>\n<p>Now we&#8217;re going to populate our datagrid with some data. dhtmlxGrid can load its content from an XML data source, so loading data into the grid is pretty simple. <\/p>\n<p>We will add one more action in <strong>\/Controllers\/AdminController.cs<\/strong>:<\/p>\n<div class=\"codecolorer-container csharp default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"csharp codecolorer\"><span class=\"kw1\">public<\/span> <span class=\"kw4\">class<\/span> AdminController <span class=\"sy0\">:<\/span> Controller<br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">public<\/span> ActionResult Index<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">return<\/span> View<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n<br \/>\n<br \/>\n&nbsp; &nbsp; <span class=\"kw1\">public<\/span> ActionResult Data<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">var<\/span> context <span class=\"sy0\">=<\/span> <span class=\"kw3\">new<\/span> GridUsersDataContext<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">return<\/span> View<span class=\"br0\">&#40;<\/span>context<span class=\"sy0\">.<\/span><span class=\"me1\">Users<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n<br \/>\n<span class=\"br0\">&#125;<\/span><\/div><\/div>\n<p>Also, let&#8217;s create one more view. The file is <strong>\/Views\/Admin\/Data.aspx<\/strong>:<\/p>\n<div class=\"codecolorer-container xml default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"xml codecolorer\"><span class=\"sc3\">&lt;%@ Page <span class=\"re0\">Language<\/span>=<span class=\"st0\">&quot;C#&quot;<\/span> <span class=\"re0\">Inherits<\/span>=<span class=\"st0\">&quot;System.Web.Mvc.ViewPage&lt;dynamic&gt;<\/span><\/span>&quot; ContentType=&quot;text\/xml&quot; %&gt;<br \/>\n<span class=\"sc3\"><span class=\"re1\">&lt;rows<span class=\"re2\">&gt;<\/span><\/span><\/span><br \/>\n&nbsp; &nbsp; <span class=\"sc3\">&lt;% foreach <span class=\"br0\">&#40;<\/span>var user in Model<span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span> %<span class=\"re2\">&gt;<\/span><\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc3\"><span class=\"re1\">&lt;row<\/span> <span class=\"re0\">id<\/span>=<span class=\"st0\">&quot;&lt;%=user.id%&gt;<\/span><\/span>&quot;&gt;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc3\"><span class=\"re1\">&lt;cell<span class=\"re2\">&gt;<\/span><\/span><\/span><span class=\"sc2\">&lt;![CDATA[&lt;%= user.first_name != null ? user.first_name : &quot;&quot; %&gt;]]&gt;<\/span><span class=\"sc3\"><span class=\"re1\">&lt;\/cell<span class=\"re2\">&gt;<\/span><\/span><\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc3\"><span class=\"re1\">&lt;cell<span class=\"re2\">&gt;<\/span><\/span><\/span><span class=\"sc2\">&lt;![CDATA[&lt;%= user.last_name != null ? user.last_name : &quot;&quot; %&gt;]]&gt;<\/span><span class=\"sc3\"><span class=\"re1\">&lt;\/cell<span class=\"re2\">&gt;<\/span><\/span><\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc3\"><span class=\"re1\">&lt;cell<span class=\"re2\">&gt;<\/span><\/span><\/span><span class=\"sc2\">&lt;![CDATA[&lt;%= user.phone != null ? user.phone : &quot;&quot; %&gt;]]&gt;<\/span><span class=\"sc3\"><span class=\"re1\">&lt;\/cell<span class=\"re2\">&gt;<\/span><\/span><\/span> &nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc3\"><span class=\"re1\">&lt;\/row<span class=\"re2\">&gt;<\/span><\/span><\/span><br \/>\n&nbsp; &nbsp; <span class=\"sc3\">&lt;% <span class=\"br0\">&#125;<\/span> %<span class=\"re2\">&gt;<\/span><\/span><br \/>\n<span class=\"sc3\"><span class=\"re1\">&lt;\/rows<span class=\"re2\">&gt;<\/span><\/span><\/span><\/div><\/div>\n<p>Inside the view we are outputting data from the <strong>Users<\/strong> table as XML.<\/p>\n<p>Our last step will be to add one more line of code in the <strong>\/Views\/Admin\/Index.aspx<\/strong> file:<\/p>\n<div class=\"codecolorer-container csharp default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"csharp codecolorer\">&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sy0\">&lt;<\/span>script type<span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/javascript&quot;<\/span> charset<span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span><span class=\"sy0\">&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">var<\/span> grid <span class=\"sy0\">=<\/span> <span class=\"kw3\">new<\/span> dhtmlXGridObject<span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;grid_here&quot;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid<span class=\"sy0\">.<\/span><span class=\"me1\">setImagePath<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;\/javascripts\/codebase\/imgs\/&quot;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid<span class=\"sy0\">.<\/span><span class=\"me1\">setHeader<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;First name, Last name, Phone&quot;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid<span class=\"sy0\">.<\/span><span class=\"me1\">setInitWidths<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;100,100,*&quot;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid<span class=\"sy0\">.<\/span><span class=\"me1\">setSkin<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;dhx_skyblue&quot;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid<span class=\"sy0\">.<\/span><span class=\"me1\">init<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid<span class=\"sy0\">.<\/span><span class=\"me1\">load<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;\/Admin\/Data?=&quot;<\/span> <span class=\"sy0\">+<\/span> grid<span class=\"sy0\">.<\/span><span class=\"me1\">uid<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><span class=\"co1\">\/\/added !<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sy0\">&lt;\/<\/span>script<span class=\"sy0\">&gt;<\/span><\/div><\/div>\n<p><b>&#8220;\/Admin\/Data?=&#8221; + grid.uid()<\/b> \u2013 here we add a unique ID to the URL so the requests won&#8217;t be cached. <\/p>\n<p>With this additional line, we&#8217;ve defined that the grid will load data from the XML we\u2019ve just created.<\/p>\n<p>Now our page is showing that the grid correctly loads the initial set of data. <\/p>\n<div id=\"attachment_427\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-427\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/07\/grid_2records.gif\" alt=\"Grid with ASP.NET MVC - Loading Records in Grid\" title=\"Grid with ASP.NET MVC - Loading Records in Grid\" width=\"600\" height=\"405\" class=\"size-full wp-image-427\" srcset=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/07\/grid_2records.gif 600w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/07\/grid_2records-300x202.gif 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><p id=\"caption-attachment-427\" class=\"wp-caption-text\">Grid with ASP.NET MVC - Loading Records in Grid<\/p><\/div>\n<p>&nbsp;<br \/>\n<strong>Saving Data to Server<\/strong><\/p>\n<p>With the previous steps completed, we created a grid that loads data from the database and displays it on a page. Now we need to add the ability to update database and save changes done by users when they edit grid records in the browser. <\/p>\n<p>On this step we\u2019ll use DataProcessor, a special extension which is available in the grid package and allows us to synchronize client-side data changes with the server-side database. To &#8220;turn on&#8221; the DataProcessor extension, we need to implement one more action. <\/p>\n<p>We add a model for action response in <strong>\/Models\/ActionResponseModel.cs<\/strong>:<\/p>\n<div class=\"codecolorer-container csharp default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"csharp codecolorer\">&nbsp; &nbsp; <span class=\"kw1\">public<\/span> <span class=\"kw4\">class<\/span> ActionResponseModel<br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">public<\/span> <span class=\"kw4\">string<\/span> Status<span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">public<\/span> <span class=\"kw4\">long<\/span> Source_id<span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">public<\/span> <span class=\"kw4\">long<\/span> Target_id<span class=\"sy0\">;<\/span><br \/>\n<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">public<\/span> ActionResponseModel<span class=\"br0\">&#40;<\/span><span class=\"kw4\">string<\/span> status, <span class=\"kw4\">long<\/span> source_id, <span class=\"kw4\">long<\/span> target_id<span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Status <span class=\"sy0\">=<\/span> status<span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Source_id <span class=\"sy0\">=<\/span> source_id<span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Target_id <span class=\"sy0\">=<\/span> target_id<span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><\/div><\/div>\n<p>We add one more action for processing of update requests in <strong>\/Controllers\/AdminController.cs<\/strong>:<\/p>\n<div class=\"codecolorer-container csharp default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;height:600px;\"><div class=\"csharp codecolorer\"><span class=\"kw1\">public<\/span> <span class=\"kw4\">class<\/span> AdminController <span class=\"sy0\">:<\/span> Controller<br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">public<\/span> ActionResult Index<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">return<\/span> View<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">public<\/span> ActionResult Data<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">var<\/span> context <span class=\"sy0\">=<\/span> <span class=\"kw3\">new<\/span> GridUsersDataContext<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">return<\/span> View<span class=\"br0\">&#40;<\/span>context<span class=\"sy0\">.<\/span><span class=\"me1\">Users<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">public<\/span> ActionResult Save<span class=\"br0\">&#40;<\/span>User changedUser, FormCollection form<span class=\"br0\">&#41;<\/span> <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw4\">string<\/span> action_type <span class=\"sy0\">=<\/span> form<span class=\"br0\">&#91;<\/span><span class=\"st0\">&quot;!nativeeditor_status&quot;<\/span><span class=\"br0\">&#93;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw4\">long<\/span> source_id <span class=\"sy0\">=<\/span> <span class=\"kw4\">long<\/span><span class=\"sy0\">.<\/span><span class=\"me1\">Parse<\/span><span class=\"br0\">&#40;<\/span>form<span class=\"br0\">&#91;<\/span><span class=\"st0\">&quot;gr_id&quot;<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw4\">long<\/span> target_id <span class=\"sy0\">=<\/span> <span class=\"kw4\">long<\/span><span class=\"sy0\">.<\/span><span class=\"me1\">Parse<\/span><span class=\"br0\">&#40;<\/span>form<span class=\"br0\">&#91;<\/span><span class=\"st0\">&quot;gr_id&quot;<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">var<\/span> context <span class=\"sy0\">=<\/span> <span class=\"kw3\">new<\/span> GridUsersDataContext<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">try<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">switch<\/span> <span class=\"br0\">&#40;<\/span>action_type<span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">case<\/span> <span class=\"st0\">&quot;inserted&quot;<\/span><span class=\"sy0\">:<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; context<span class=\"sy0\">.<\/span><span class=\"me1\">Users<\/span><span class=\"sy0\">.<\/span><span class=\"me1\">InsertOnSubmit<\/span><span class=\"br0\">&#40;<\/span>changedUser<span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">break<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">case<\/span> <span class=\"st0\">&quot;deleted&quot;<\/span><span class=\"sy0\">:<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; changedUser <span class=\"sy0\">=<\/span> context<span class=\"sy0\">.<\/span><span class=\"me1\">Users<\/span><span class=\"sy0\">.<\/span><span class=\"me1\">SingleOrDefault<\/span><span class=\"br0\">&#40;<\/span>u <span class=\"sy0\">=&gt;<\/span> u<span class=\"sy0\">.<\/span><span class=\"me1\">id<\/span> <span class=\"sy0\">==<\/span> source_id<span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; context<span class=\"sy0\">.<\/span><span class=\"me1\">Users<\/span><span class=\"sy0\">.<\/span><span class=\"me1\">DeleteOnSubmit<\/span><span class=\"br0\">&#40;<\/span>changedUser<span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">break<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">default<\/span><span class=\"sy0\">:<\/span> <span class=\"co1\">\/\/ &quot;updated&quot; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; changedUser <span class=\"sy0\">=<\/span> context<span class=\"sy0\">.<\/span><span class=\"me1\">Users<\/span><span class=\"sy0\">.<\/span><span class=\"me1\">SingleOrDefault<\/span><span class=\"br0\">&#40;<\/span>u <span class=\"sy0\">=&gt;<\/span> u<span class=\"sy0\">.<\/span><span class=\"me1\">id<\/span> <span class=\"sy0\">==<\/span> source_id<span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UpdateModel<span class=\"br0\">&#40;<\/span>changedUser<span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">break<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; context<span class=\"sy0\">.<\/span><span class=\"me1\">SubmitChanges<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; target_id <span class=\"sy0\">=<\/span> changedUser<span class=\"sy0\">.<\/span><span class=\"me1\">id<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">catch<\/span> <span class=\"br0\">&#40;<\/span>Exception e<span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; action_type <span class=\"sy0\">=<\/span> <span class=\"st0\">&quot;error&quot;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">return<\/span> View<span class=\"br0\">&#40;<\/span><span class=\"kw3\">new<\/span> ActionResponseModel<span class=\"br0\">&#40;<\/span>action_type, source_id, target_id<span class=\"br0\">&#41;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp;<br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><\/div><\/div>\n<p>That&#8217;s quite a big piece of code, comparing to our previous steps. In our new Save method, we are doing the following:<\/p>\n<ul>\n<li>Getting the type of operation: inserted, updated or deleted<\/li>\n<li>Getting the ID of a grid row<\/li>\n<\/ul>\n<p>&nbsp;<br \/>\nNow the code executes logic for each operation: it adds a new user (a row in the table) for &#8220;inserted&#8221;; it deletes and updates user info for &#8220;deleted&#8221; and &#8220;inserted&#8221; operations.<\/p>\n<p>In addition to this action, we need to create one more XML view, which will be a response to an update operation. In the file <strong>\/Views\/Admin\/Save.aspx<\/strong>:<\/p>\n<div class=\"codecolorer-container csharp default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"csharp codecolorer\"><span class=\"sy0\">&lt;%<\/span>@ Page Language<span class=\"sy0\">=<\/span><span class=\"st0\">&quot;C#&quot;<\/span> Inherits<span class=\"sy0\">=<\/span><span class=\"st0\">&quot;System.Web.Mvc.ViewPage&lt;dynamic&gt;&quot;<\/span> ContentType<span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/xml&quot;<\/span><span class=\"sy0\">%&gt;<\/span><br \/>\n<span class=\"sy0\">&lt;<\/span>data<span class=\"sy0\">&gt;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"sy0\">&lt;<\/span>action type<span class=\"sy0\">=<\/span><span class=\"st0\">&quot;&lt;%= Model.Status %&gt;&quot;<\/span> sid<span class=\"sy0\">=<\/span><span class=\"st0\">&quot;&lt;%= Model.Source_id %&gt;&quot;<\/span> tid<span class=\"sy0\">=<\/span><span class=\"st0\">&quot;&lt;%= Model.Target_id %&gt;&quot;<\/span><span class=\"sy0\">&gt;&lt;\/<\/span>action<span class=\"sy0\">&gt;<\/span><br \/>\n<span class=\"sy0\">&lt;\/<\/span>data<span class=\"sy0\">&gt;<\/span><\/div><\/div>\n<p>The &#8220;Model.Target_id&#8221; parameter in the above code provides a new ID value, which can (and will) be changed after the insert operation. The grid creates a temporary ID for a new record, which needs to be changed with an actual ID after saving the grid data. <\/p>\n<p>The server-side part is ready, so we only need to point our grid to the dbaction feed. We add in <strong>\/Views\/Admin\/Index.aspx<\/strong>:<\/p>\n<div class=\"codecolorer-container html4strict default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;height:600px;\"><div class=\"html4strict codecolorer\"><span class=\"sc2\">&lt;%@ Page <span class=\"kw3\">Language<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;C#&quot;<\/span> Inherits<span class=\"sy0\">=<\/span><span class=\"st0\">&quot;System.Web.Mvc.ViewPage&lt;dynamic&gt;<\/span><\/span>&quot; %&gt;<br \/>\n<br \/>\n<span class=\"sc0\">&lt;!DOCTYPE HTML PUBLIC &quot;-\/\/W3C\/\/DTD HTML 4.01 Transitional\/\/EN&quot;<\/span><br \/>\n<span class=\"sc0\">&nbsp; &nbsp; &quot;http:\/\/www.w3.org\/TR\/html4\/loose.dtd&quot;&gt;<\/span><br \/>\n<span class=\"sc2\">&lt;<span class=\"kw2\">html<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp;<span class=\"sc2\">&lt;<span class=\"kw2\">head<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">script<\/span> <span class=\"kw3\">src<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;\/Scripts\/dhtmlxcommon.js&quot;<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/javascript&quot;<\/span> <span class=\"kw3\">charset<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span>&gt;&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">script<\/span> <span class=\"kw3\">src<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;\/Scripts\/dhtmlxgrid.js&quot;<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/javascript&quot;<\/span> <span class=\"kw3\">charset<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span>&gt;&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">script<\/span> <span class=\"kw3\">src<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;\/Scripts\/dhtmlxgridcell.js&quot;<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/javascript&quot;<\/span> <span class=\"kw3\">charset<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span>&gt;&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">link<\/span> <span class=\"kw3\">rel<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;stylesheet&quot;<\/span> <span class=\"kw3\">href<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;\/Scripts\/dhtmlxgrid.css&quot;<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/css&quot;<\/span> <span class=\"kw3\">media<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;screen&quot;<\/span> <span class=\"kw3\">charset<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">link<\/span> <span class=\"kw3\">rel<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;stylesheet&quot;<\/span> <span class=\"kw3\">href<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;\/Scripts\/skins\/dhtmlxgrid_dhx_skyblue.css&quot;<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/css&quot;<\/span> <span class=\"kw3\">media<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;screen&quot;<\/span> <span class=\"kw3\">charset<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">script<\/span> <span class=\"kw3\">src<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;\/Scripts\/dhtmlxdataprocessor.js&quot;<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/javascript&quot;<\/span> <span class=\"kw3\">charset<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span>&gt;&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">head<\/span>&gt;<\/span> &nbsp; &nbsp;<br \/>\n<br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">body<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">div<\/span> <span class=\"kw3\">id<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;grid_here&quot;<\/span> <span class=\"kw3\">style<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;width:600px; height:400px;&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">div<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">script<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/javascript&quot;<\/span> <span class=\"kw3\">charset<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var grid = new dhtmlXGridObject(&quot;grid_here&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.setImagePath(&quot;\/Scripts\/imgs\/&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.setHeader(&quot;First name, Last name, Phone&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;grid.setColumnIds(&quot;first_name,last_name,phone&quot;);\/\/!added<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.setInitWidths(&quot;100,100,*&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.setSkin(&quot;dhx_skyblue&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.init();<br \/>\n<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.load(&quot;\/Admin\/Data?=&quot; + grid.uid());<br \/>\n<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dp = new dataProcessor(&quot;\/Admin\/Save&quot;);\/\/!added<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dp.setTransactionMode(&quot;POST&quot;, false);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dp.enableDataNames(true);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dp.init(grid);<br \/>\n<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">input<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;button&quot;<\/span> <span class=\"kw3\">value<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;Add&quot;<\/span> <span class=\"kw3\">onclick<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;add();&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">input<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;button&quot;<\/span> <span class=\"kw3\">value<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;Delete&quot;<\/span> <span class=\"kw3\">onclick<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;remove();&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">body<\/span>&gt;<\/span><br \/>\n<span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">html<\/span>&gt;<\/span><\/div><\/div>\n<p>With this code, we are:<\/p>\n<ul>\n<li>Including one more file to activate DataProcessor<\/li>\n<li> grid.setColumnIds(&#8220;first_name,last_name,phone&#8221;) \u2013 setting IDs to the grid columns (we used property names used in the model User)<\/li>\n<li>Adding four JS lines to initialize DataProcessor, pointing it to the Save action <\/li>\n<li>Adding buttons to add and delete rows in the grid<\/li>\n<\/ul>\n<p>&nbsp;<br \/>\nYou can now try to edit the grid records, add or remove grid rows. You will see that all changes are saved in the database automatically.  <\/p>\n<p>The way to make &#8220;inserted&#8221; function work is: <\/p>\n<ul>\n<li>Click &#8220;Add&#8221; button. A new row with some default values will be added in the end of the grid.<\/li>\n<li>Enter real values in the cells of the new row. <\/li>\n<\/ul>\n<p>&nbsp;<br \/>\nThe new row will be saved into the database table. Refresh the page and you will see all the changes you&#8217;ve just made.<\/p>\n<p><strong>Extra Functionality<\/strong><\/p>\n<p>If you remember, we were going to create a grid with sorting and filtering capabilities. These features can be added to our grid without any changes in the server-side logic. <\/p>\n<p>We enable client-side filtering and sorting by adding the following code to the <strong>\/Views\/Admin\/Index.aspx<\/strong> file:<\/p>\n<div class=\"codecolorer-container html4strict default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"html4strict codecolorer\">&lt;<span class=\"kw2\">script<\/span> <span class=\"kw3\">src<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;\/Scripts\/ext\/dhtmlxgrid_filter.js&quot;<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/javascript&quot;<\/span> <span class=\"kw3\">charset<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span>&gt;&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; ...<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &lt;<span class=\"kw2\">script<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/javascript&quot;<\/span> <span class=\"kw3\">charset<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span>&gt;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var grid <span class=\"sy0\">=<\/span> new dhtmlXGridObject<span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;grid_here&quot;<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.setImagePath<span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;\/Scripts\/imgs\/&quot;<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.setHeader<span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;First name, Last name, Phone&quot;<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.attachHeader<span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;#text_filter,#text_filter,#text_filter&quot;<\/span><span class=\"br0\">&#41;<\/span>; <span class=\"sy0\">\/\/<\/span>added !<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.setColSorting<span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;str,str,str&quot;<\/span><span class=\"br0\">&#41;<\/span>; &nbsp;<span class=\"sy0\">\/\/<\/span>added !<\/div><\/div>\n<p>Finally, we have a datagrid which uses client-side logic to perform sorting and filtering of data, and manages data communication with ASP.NET MVC on the backend. <\/p>\n<div id=\"attachment_429-2\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-429-2\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/07\/ready_grid.gif\" alt=\"Grid with ASP.NET MVC - Editable Grid\" title=\"Grid with ASP.NET MVC - Editable Grid\" width=\"600\" height=\"405\" class=\"size-full wp-image-427\" \/><p id=\"caption-attachment-429-2\" class=\"wp-caption-text\">Grid with ASP.NET MVC - Editable Grid<\/p><\/div>\n<p>By clicking on the header you can sort the grid by any column. Typing text in input fields in the header will filter the grid records by entered text. When you edit records in the grid, the changes will be saved in the database automatically, as well as row addition and deletion (use the buttons below the grid). <\/p>\n<p>You can download the <a href=\"https:\/\/dhtmlx.com\/x\/download\/regular\/tutorials\/dhtmlxGrid_net_mvc.zip\">full source code of the resulting demo<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial we are going to explain how to use dhtmlxGrid with ASP.NET MVC. Following this article step by step will allow you to implement an editable datagrid &#8230;<\/p>\n","protected":false},"author":2,"featured_media":3454,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[71,1],"tags":[33,37,6,14],"class_list":["post-1349","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","category-uncategorized","tag-all-posts","tag-asp-net","tag-dhtmlxgrid","tag-tips"],"_links":{"self":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/1349","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/comments?post=1349"}],"version-history":[{"count":3,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/1349\/revisions"}],"predecessor-version":[{"id":13918,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/1349\/revisions\/13918"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/media\/3454"}],"wp:attachment":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/media?parent=1349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/categories?post=1349"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/tags?post=1349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}