Datasource is a very important data access control in 2.0. However, in the design view, datasource controls always render a gray pie with no information except the ID. It seems not so nice. However, we have discovered the namespace system. Web. UI. Design. webcontrols, "containing classes that can be used to expand the Design Support for Web server controls ". So I tried the most useful objectdatasource and the result was as follows:
The above is the custom datasource, which displays common attributes in the design view, making it easier to use. The following is the main code:
Veryobjectdatasource
[Displayname ( " Veryobjectoatasource " ), Description ( " Verydxz's objectdatasource " )]
[Designer ( " Dxz. Common. databinding. veryobjectperformancedesigner " )]
Public Class Veryobjectdatasource: objectdatasource
{
}
Public Class Veryobjectperformancedesigner: system. Web. UI. Design. webcontrols. objectperformancedesigner
{
Public Override String Getdesigntimehtml ()
{
Veryobjectdatasource veryods = (Veryobjectdatasource) This . Component;
Stringbuilder htmlstrbuilder = New Stringbuilder ();
Htmlstrbuilder. append ( " <Div style = 'margin: 2px; padding: 2px; Background-color: buttonface; color: windowtext; Font: MessageBox; '> " );
Htmlstrbuilder. appendformat ( " <Strong> {0} </strong>-{1} <br/> " , Veryods. GetType (). Name, veryods. ID );
If (Veryods. typename ! = Null && Veryods. typename ! = String . Empty)
Htmlstrbuilder. appendformat ( " Typename = {0} <br/> " , Veryods. typename );
If (Veryods. dataobjecttypename ! = Null && Veryods. dataobjecttypename ! = String . Empty)
Htmlstrbuilder. appendformat ( " Dataobject = {0} <br/> " , Veryods. dataobjecttypename );
If (Veryods. selectmethod ! = Null && Veryods. selectmethod ! = String . Empty)
{
Htmlstrbuilder. append ( " Hasmethod = select " );
If (Veryods. insertmethod ! = Null && Veryods. insertmethod ! = String . Empty)
Htmlstrbuilder. append ( " , Insert " );
If (Veryods. updatemethod ! = Null && Veryods. updatemethod ! = String . Empty)
Htmlstrbuilder. append ( " , Update " );
If (Veryods. deletemethod ! = Null && Veryods. deletemethod ! = String . Empty)
Htmlstrbuilder. append ( " , Delete " );
Htmlstrbuilder. appendformat ( " <Br/> caching = {0}, paging = {1} " , Veryods. enablecaching, veryods. enablepaging );
}
Htmlstrbuilder. append ( " </Div> " );
Return Htmlstrbuilder. tostring ();
}
}
Note the attribute of the veryobjectdatasource class:
[Designer ("Dxz. Common. databinding. veryobjectperformancedesigner")].
If no such clause is provided, the control will not be render according to the custom clause. For the source code, see here
The above is just a custom appearance. Of course, some initialization parameters can be added to the objectdatasource constructor to facilitateProgramDesigned for use. At the same time, this custom appearance method is also applicable to controls such as XML and substitution with no content provided by render.