[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Collapse]eXpress Persistent Objects
 [Expand]Product Information
 [Collapse]Getting Started
   Tutorial 1 - Your First Data-Aware Application with XPO
   Tutorial 2 - Relations (One to Many)
   Tutorial 3 - Querying Data
   Tutorial 4 - A Windows Forms Application for Data Editing
   Tutorial 5 - An ASP .NET Application for Data Editing
   Tutorial 6 - A Simple Guestbook (ASP.NET)
   Getting Started with .NET Core
 [Expand]Feature Center
 [Expand]Design-Time Features
 [Expand]Member Tables
 [Expand]API Reference
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Tutorial 5 - An ASP .NET Application for Data Editing


To create a simple ASP.NET application to view and edit customer details.



Expanded Define a Persistent Object Class

Once a new project has been created, we need to define a persistent object class. To do this, the new class is added to the project. Make it the Customer class.

The FirstName, LastName and Company properties of this class represent the values of the corresponding fields in a database table.

Please note that the property implementations in this sample don't have all code in their setters that we recommend. We have shortened the sample code for brevity and simplicity. Follow our tutorials to learn the recommended way of implementing property setters.

Expanded Connect to a Database Server

Connect XPO to a database server. To do this, create an IDataLayer object. The code which creates the data layer must be placed inside the Application_Start event handler in the Global.asax module of your Web Site. For more information, see Connecting XPO to a Database Server (ASP.NET).

Expanded Retrieve Data Using the XpoDataSource Component

Persistent objects are retrieved from a database using the XpoDataSource component. After we have declared the Customer class, it's necessary to rebuild our solution, drag the XpoDataSource component from the Toolbox and drop it onto the page. Then, assign our persistent class to the TypeName property as shown below:

Link the XpoDataSource component to a session:

To display data, you need to assign the XpoDataSource component to a control used to represent data. In this example, we use our ASPxGridView component. The image below shows how to bind the XpoDataSource to the grid.

After the XpoDataSource has been bound to the grid, the grid automatically generates data columns for all persistent properties (fields in a table). Enable data editing as shown below:

Finally, add records to the Customer table and run the project.

The animation below shows the result.

A user can view and edit data in the grid. You don't have to write any code to save data: all changes are automatically persisted with the next post-back to the server.


Expanded Results

  • We've created a simple ASP.NET application that allows end-users to view and edit customer details. Data is stored in the MS Access database (Customer.mdb) which resides in the App_Data folder.
  • We've declared the Customer class whose instances represent records in the Customer table.
  • You learned how to use the XpoDataSource component.

Expanded See Also

Is this topic helpful?​​​​​​​