In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about how to bind ASP.NET 2.0 data. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something from this article.
1. Why can ASP.NET 2.0 data-bound controls complete update, delete, new and other data operations without writing code?
In ASP.NET 1.x, controls such as DataGrid use expressions such as DataBinder.Eval (Container.DataItem, "ColumnName") to bind the data from the data source to the control, but they cannot automatically take out the new values in the control and update them back to the database when the data is updated. So there are two types of ASP.NET 2.0 data binding: one-way data binding (that is, BoundField whose expression or ReadOnly is set to True, which only provides data binding from the data source to the control) and two-way data binding (which not only binds data from the data source to the control, but also provides the data in the control to the data source control when manipulating the data). So ASP.NET 2.0 doesn't need to write a lot of code like e.Item.FindControl () when manipulating data.
2. In the process of Update and Insert, how does GridView/DetailsView/FormView pass the value to the data source control so that the data source control can complete the call of the data operation method?
When updating, GridView will provide two sets of values to the data source control, a new set of values, which collects the values of all the columns whose ReadOnly is not True and the values of all expressions in the template, and the other set of old values, which are obtained from the DataKey corresponding to the current row (the value of DataKey will be saved to view state by GridView when binding data), which can be seen in GridView's Updating event handler. When the old set of values is provided to the data source control, its Key is renamed by the data source control according to the OldValuesParameterFormatString. For example, if the DataKeyNames in GridView is set to ProductID and the OldValuesParameterFormatString of the data source control is original_ {0}, then GridView will have an original_ProductID in the parameters passed to the data source control when it is updated.
The combination of the new set of values and the old set of values should match exactly the list of parameters needed by the data source control, neither more nor less, which is the most common problem encountered by beginners when using GridView to update data.
In actual use, if the parameter corresponding to the primary key column (for example, ProductID) is not named original_ProductID as Strong named Dataset, you need to change the OldValuesParameterFormatString of the data source, such as {0}, so that it corresponds to the parameters of the implementation method.
3. How to realize open concurrency?
Open concurrent update and delete statements have a long where clause, such as:
Strongly typed datasets can automatically generate such commands by selecting the open concurrency check box on advanced options. According to our point 2, just add all the fields in the DatakeyNames property of GirdView, so that the old values will be automatically put into the old value collection to meet the requirements of the data source. From this, we can understand why the DataKeyField (singular) attribute of DataGrid is replaced with the DataKeyNames attribute (plural). The above introduction to ASP.NET 2.0 data binding
After reading the above, do you have any further understanding of how to do ASP.NET 2.0 data binding? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.