简体   繁体   中英

How to bind data from webservice to DevExpress gridview in ASP.NET and to use CRUD operations on the data?

I'm consuming SOAP webservice to my ASP.NET project that use DevExpress controls. What I'm trying to do is to get data from the webservice and bind it to the DevExpress gridcontrol.

When consuming the webservice I get some IEnumerable container. Is it possible to create some kind og dynamic relationship between the webservice and the Devexpress gridcontrol? I want to be able to use CRUD operations on each record in the IEnumerable container that will return back to webservice after user input [POST]

What is the best way to make bridge between the webservice and the gridcontrol [GET and POST form the gridview]?

My recommendation is to write a helper class to handle CRUD operations for you, separate from the DevExpress controls.

It's always a good idea to separate the display logic from the business logic ( MVC style ) by having an intermediary class handle CRUD operations to and from the data source. This allows us to makes changes to the data source (the web service in your case) in one location, without breaking any other code. We could even change the data source from a webservice to SQL Server (or MySQL or anything at all) without having to adjust the front end.

As far as binding to DevExpress controls, you will need to handle the CRUD row events individually - they have some great examples and very good documentation . You should probably read up on databinding in general for more advanced options, but we typically do something like the following (in the code-behind) for a CRUD events coming from DevExpress controls on an ASP.NET page:

  1. Instantiate an object representing a data record (by retrieving it from the datasource using our helper class if it's an existing record): var Record = new Record(); or var Record = RecordHelper.GetWithId(PrimaryKeyValue);
  2. Make changes to that object as required: Record.Name = "New Name";
  3. Pass the object back to a method in our helper class, which handles the necessary adjustments to the data source: RecordHelper.Insert(Record); or RecordHelper.Update(Record);
  4. Update the grid on the page (as required)

You could write some sort of subclass that would handle the binding and updating for you, or start reading up on approaches like the Entity Framework , but I would recommend starting as above so you understand the interaction between DevExpress controls and your database.


ps This MSDN article is a good place to start learning some really easy but powerful 2-way data binding. This is probably what you were looking for in the first place; if you happen to be using .NET 4.5, note that it provides strongly-typed databinding, which makes life even easier.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM