[Original] let the objectdatasource in layer-3 Support griedview without writing code with editing function

Source: Internet
Author: User

The griedview with objectdatasource as the data source in the mixed layer can be quickly edited. I believe this pair has been written so that the DataGrid has the same function, the hard work done by the people is nothing different! Hoho, I am one of them. The following describes two methods implemented in a three-tier architecture:
First, use the generic dataset provided by Microsoft as the Dal. The operation steps in this method are simple in the wizard, but the efficiency is low, and the mouse point is time-consuming, for detailed operation steps, see http://www.cnblogs.com/eddie005/archive/2006/08/01/425273.htmto create data transport layer (DAL), logic layer (BLL), and use objectdatasource to present data.
Second: This is the method recommended in this article, with the help of third-party. netCodeGenerate tool, such as Niu Ren Li Tianping's dynamic soft. Net Code Automatic Generator (http://www.maticsoft.com/softdown.aspx), which is used as the code generation tool below. Run the code generation tool to generate model (Table generic object), Dal, and BLL. Next, add a delete polymorphism method to Dal and BLL. The method parameter is model, that is, for example:

 

How to delete a data Polymorphism
1
2 Public   Void Delete (Products Model)
3 {
4 Stringbuilder strsql =   New Stringbuilder ();
5 Strsql. append ( " Delete Products " );
6 Strsql. append ( " Where productid = @ productid " );
7 Sqlparameter [] Parameters =   {
8NewSqlparameter ("@ Productid", Sqldbtype. Int,4)
9} ;
10 Parameters [ 0 ]. Value = Model. productid;
11 Dbhelpersql. dbhelpersql. executesql (strsql. tostring (), parameters );
12 }

Add corresponding methods in BLL.
in the presentation layer, drag an objectdatasource control and set its data source to BLL. When setting its data operation method, delete: select the object method as the new parameter. Drag a gridview and specify its data source as the objectdatasource
Control ID. Do not forget to enable the Edit function of the gridview and set the datakeyname attribute. Finally, preview the acceptance result, delete and update shards!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.