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!