1, why asp.net 2.0 data-bound controls do not need to write code to complete the update, delete, new and other data operations?
ASP.net 1.x, a control such as the DataGrid uses an expression such as DataBinder.Eval (Container.DataItem, "ColumnName") to bind data from the data source to the control. However, it is not possible to automatically remove new values from the control while updating the data back to the database. So there are two types of data binding in asp.net 2.0: one-way data binding (either an expression or a BoundField with a readonly set to True, only data binding from a data source to a control), and bidirectional data binding (not only can you bind data from a data source to a control, And the data in the control can be supplied to the data source control when the data is manipulated, so ASP.net 2.0 does not need to write a lot of e when manipulating the data. Item.findcontrol () code like this.
2. During the update and insert process, how does the Gridview/detailsview/formview pass the value to the data source control so that the data source control completes the invocation of the data manipulation method?
When updated, the GridView provides two sets of values to the data source control, a new set of values, a collection of values for all readonly columns that are not true, and the value of all expressions in the template, and the other old values, which are derived from the datakey corresponding to the current row ( DataKey values are saved to view state by the GridView when binding data, which can be seen in the GridView updating event handler. When the old set of values is supplied to the data source control, its key is renamed by the data source control based on OldValuesParameterFormatString. For example, the DataKeyNames in the GridView is set to ProductID, and the oldvaluesparameterformatstring of the data source control is original_{0}, Then there is a original_productid in the parameters of the GridView passed to the data source control when it is updated.
The new set of values combined with the old set of values just matches the list of parameters needed by the data source control, not much or less, which is the most common problem for beginners when updating data with the GridView.
If the corresponding parameter of the primary key column (for example, ProductID) is not named Original_productid as the fervent named DataSet during the actual use, You need to change the oldvaluesparameterformatstring of the data source, such as {0}, so that you can match the parameters of the implementation method.
3. How to achieve optimistic concurrency?
Optimistic concurrent update and deletion statements have a long where clause, such as:
Update Table1 Set Column1 = @Column1, Column2 = @Column2 where ID = @original_ID and Column1 = @orignal_Column1 and Column2 = @ori Ginal_column2;
A strongly typed dataset automatically generates such a command by selecting an optimistic concurrent selection on the Advanced option. According to our 2nd argument, just add all the fields to the Girdview datakeynames attribute, which automatically puts the old values in the old values collection to meet the requirements of the data source. Thus, we can understand why the DataKeyField (singular) attribute of the DataGrid is replaced with the DataKeyNames attribute (plural).
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.