1. Why does the data binding control in ASP. NET 2.0 complete data operations such as update, deletion, and creation without writing code?
In ASP. net 1. x, databinder is used for DataGrid and other controls. eval (container. dataitem, "columnname") can bind data in the data source to the control, but it cannot automatically retrieve the new value of the control during data update and update it back to the database. So ASP. NET 2.0 Data Binding can be divided into one-way data binding (that is, the <% # eval ("columnname") %> expression or the boundfield where readonly is set to true, only data binding from the data source to the control is provided) and two-way data binding (<% # BIND ("columnname") %> can not only bind data from the data source to the control, in addition, the data in the control can be provided to the data source control during data operations), so ASP. NET 2.0 does not need to write a large number of E. item. findcontrol.
2. During update and insert, how does the gridview/detailsview/formview pass the value to the data source control so that the data source control can call the data operation method?
When updating, the gridview provides two sets of values to the data source control. A new set of values aggregates the values of all columns whose readonly is not true and all <% # BIND () in the template () %> the expression value and the other old value are obtained from the datakey corresponding to the current row (the datakey value is saved to the view State by the gridview when data is bound ), you can see this feature in the updating event handler of the gridview. After the old value is provided to the data source control, its key is renamed by the data source control according to oldvaluesparameterformatstring. For example, if datakeynames in the gridview is set to productid and the oldvaluesparameterformatstring of the data source control is original _ {0}, an original_productid is generated in the parameters passed to the data source control when the gridview is updated.
The new value and the old value must match the parameter list required by the data source control, this is the most common problem for beginners when using the gridview to update data.
In actual use, if the parameter (for example, productid) corresponding to the primary key column is not named original_productid as in strong named dataset, you need to change the oldvaluesparameterformatstring of the data source to {0 }, in this way, the parameters of the implementation method can be matched.
3. How to Implement Open concurrency?
An open and concurrent update and delete statement has a long where clause, for example:
Update Table1 set column1 = @ column1, column2 = @ column2 where id = @ original_id and column1 = @ orignal_column1 and column2 = @ original_column2. A strongly typed dataset can automatically generate such a command by selecting the option of open concurrency on the advanced option. According to our discussion at, we only need to add all the fields in the datakeynames attribute of girdview, so that the old values will be automatically put into the old value set, meets the requirements of the data source. Therefore, we can understand why the datakeyfield (singular) attribute of the DataGrid is replaced with the datakeynames attribute (plural ).