Introduction to ASP. NET 2.0 Data Binding

Source: Internet
Author: User

1. Why does the ASP. NET 2.0 data binding control 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 is divided into two types: one-way data binding (that is, the expression or ReadOnly is set to True BoundField, only the data binding from the data source to the control is provided) and two-way data binding (, you can not only bind data from the data source to the control, but also provide the data in the control to the data source control when operating the data), 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 data source, 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 value is not True and the values of all expressions in the template, another set of old values is 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:

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 ). The above introduces ASP. NET 2.0 Data Binding

  1. Introduction to ASP. net mvc Framework
  2. Introduction to MvcAjaxPanel in ASP. NET MVC
  3. ASP. net mvc Framework to save UpdatePanel
  4. Use ASP. net mvc source code to find a solution
  5. ActionInvoker of ASP. net mvc Framework

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.