In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how to use the DataObjectTypeName property of the ObjectDataSource control in ASP.NET. I hope you will get something after reading this article. Let's discuss it together.
1. ObjectDataSource control description
Gets or sets the name of a class that the ObjectDataSource control uses to update, insert, or delete parameters in data operations, rather than passing individual values from the data-bound control.
Instead of specifying multiple parameters passed to the Update, Insert, and Delete methods, you can create an object that accumulates multiple data field values. Only this one object is passed to the method, not multiple parameters.
The default behavior of an ObjectDataSource control bound to a data-bound control is that the data-bound control creates a Parameter object for each parameter in the data source. If the business object has many fields, the resulting method also has many fields. The DataObjectTypeName property allows you to specify a type with attributes for each data field. Instead of passing multiple parameters to the method, the runtime creates an object and sets all its properties. This object is added to the parameter collection of the method call.
Second, the use of the DataObjectTypeName attribute
The type specified by the DataObjectTypeName property must have a default constructor with no arguments so that the ObjectDataSource control can create an instance of this type. This type must also have settable properties that allow the ObjectDataSource control to populate the object with the values passed by the data-bound control. The property name of the ObjectDataSource control should exactly match the parameter name of the value passed by the data-bound control.
When the DataObjectTypeName property is set and the ObjectDataSource control is associated with a data-bound control, the methods specified by the InsertMethod and DeleteMethod properties must each have a parameter of the type specified in the DataObjectTypeName property. If the ConflictDetection property is set to the OverwriteChanges value, the method specified by the UpdateMethod property must have a parameter of the type specified in the DataObjectTypeName property. If the ConflictDetection property is set to the CompareAllValues value, the method specified by the UpdateMethod property must have two parameters of the type specified in the DataObjectTypeName property. The first parameter contains the original value; the second parameter contains the new value.
The DataObjectTypeName property delegates to the DataObjectTypeName property of the ObjectDataSourceView associated with the ObjectDataSource control.
Sample code
The following code example shows how to use the DataObjectTypeName property to implement a type that combines all parameter values into a single object. The selection method of the AggregateData class returns a DataTable object with two columns named Name and Number. Similarly, the NewData class defines two read / write properties, Name and Number. The Insert method of the AggregateData class takes a parameter of type NewData. The TypeName property of the ObjectDataSource is set to the AggregateData,DataObjectTypeName property to NewData.
Foreground code:
ObjectDataSource-DataObjectTypeName Property Example
Background code:
Using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;namespace Samples.AspNet.CS {/ Summary description for AggregateData / public class AggregateData {public AggregateData () {} static DataTable table; private DataTable CreateData () {table = new DataTable () Table.Columns.Add ("Name", typeof (string)); table.Columns.Add ("Number", typeof (int)); table.Rows.Add (new object [] {"one", 1}); table.Rows.Add (new object [] {"two", 2}); table.Rows.Add (new object [] {"three", 3}); return table } public DataTable Select () {if (table = = null) {return CreateData ();} else {return table;}} public int Insert (NewData newRecord) {table.Rows.Add (new object [] {newRecord.Name, newRecord.Number}); return 1;} public class NewData {private string nameValue; private int numberValue Public string Name {get {return nameValue;} set {nameValue = value;}} public int Number {get {return numberValue;} set {numberValue = value After reading this article, I believe you have a certain understanding of "how to use the DataObjectTypeName property of ObjectDataSource controls in ASP.NET". If you want to know more about it, please follow the industry information channel. Thank you for reading!
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.