Dataobjecttypename attribute of objectdatasource

Source: Internet
Author: User

Gets or sets the name of a class. The objectdatasource control uses this class to update, insert, or delete parameters in a data operation, rather than passing individual values from the data binding 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 object is passed to the method, not multiple parameters.

The default behavior of the objectdatasource control bound to the data binding control is that the data binding control creates a parameter object for each parameter in the data source. If the business object has many fields, the result method also has many fields. The dataobjecttypename attribute allows you to specify an attribute type for each data field. In this way, the runtime does not pass multiple parameters to the method, but creates an object and sets all its attributes. This object is added to the parameter set of the method call.

The data type specified by the dataobjecttypename attribute must have a default constructor without parameters, so that the objectdatasource control can create instances of this type. This type must also have configurable properties that allow the objectdatasource control to fill objects with values passed by the data binding control. The property name of the objectdatasource control should exactly match the parameter name of the value passed by the data binding control.

When the dataobjecttypename attribute is set and the objectdatasource control is associated with the data binding control, each method specified by the insertmethod and deletemethod attribute must have a parameter of the type specified in the dataobjecttypename attribute. If the conflictdetection attribute is set to the overwritechanges value, the method specified by the updatemethod attribute must have a parameter of the type specified in the dataobjecttypename attribute. If the conflictdetection attribute is set to the compareallvalues value, the method specified by the updatemethod attribute must have two parameters of the type specified in the dataobjecttypename attribute. The first parameter contains the original value, and the second parameter contains the new value.

The dataobjecttypename attribute delegated to the dataobjecttypename attribute associated with the objectdatasourceview of the objectdatasource control.

 

Example
--------------------------------------------------------------------------------

This section contains twoCodeExample. The first sample code demonstrates how to use the dataobjecttypename attribute to merge all parameter values into an object type. The second code example demonstrates the use of two types of web pages in the first example.

The following code example demonstrates how to use the dataobjecttypename attribute to merge all parameter values into an object type. The selection method of the aggrespondata class returns a datatable object with two columns named name and number. Similarly, the newdata class defines two read/write attributes: name and number. The insert method of the aggrespondata class includes a parameter of the newdata type. The typename attribute of objectdatasource is set to aggrespondata, And the dataobjecttypename attribute is set to newdata.

 

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;

NamespaceSamples. ASPnet. CS
{

//


// summary description for aggrespondata
///
Public class aggrespondata
{

PublicAggrespondata ()
{

}

StaticDatatable 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;
}< BR >}

Public int insert (newdata newrecord)
{< br> table. rows. add ( New Object [] {newrecord. name, newrecord. number});
return 1 ;
}< BR >}

Public class newdata
{< br> private string namevalue;
private int numbervalue;

Public string name
{< br> Get { return namevalue ;}
set {namevalue = value ;}
}

Public IntNumber
{
Get{ReturnNumbervalue ;}
Set{Numbervalue=Value ;}
}

}
}

 

 

 

Code

<% @ Register tagprefix = " Aspsample " Namespace = " Samples. ASPnet. CS " Assembly = " Samples. ASPnet. CS "   %>
<% @ Page Language = " C # "   %>

<!Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<ScriptRunat= "Server">

</Script>

< Html Xmlns = "Http://www.w3.org/1999/xhtml"   >
< Head Runat = "Server" >
< Title > Objectdatasource-dataobjecttypename property example </ Title >
</ Head >
< Body >
< Form ID = "Form1" Runat = "Server" >
< Div >
< ASP: detailsview
ID = "Detailsview1"  
Runat = "Server"  
Allowpaging = "True"  
Autogenerateinsertbutton = "True"
Performanceid = "Objectperformance1"  
Height = "50px"  
Width = "125px" >
</ ASP: detailsview >
< ASP: objectdatasource
ID = "Objectperformance1"  
Runat = "Server"  
Dataobjecttypename = "Samples. ASPnet. cs. newdata"
Insertmethod = "Insert"  
Selectmethod = "Select"  
Typename = "Samples. ASPnet. cs. aggrespondata" >
</ ASP: objectdatasource >
</ Div >
</ Form >
</ Body >
</ Html >

 

 

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.