Customize the design view appearance of the objectdatasource Control

Source: Internet
Author: User
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.
 

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.