First twoArticleI have developed a paging control based on the Web architecture, a very common control.
When you use the gridview, when you put the control into the page, a small triangle will appear in the upper right corner of the Control. Click it to apply the format automatically, click a different format to view the effect on the right side.
Previously, the above controls only display Chinese styles by default. Later I saw other people's articles on the Internet using a similar method, and I wanted to add an English style to my controls.
Legend:
How can we make the control have this function?
Step 1:
[Designer (typeof (aspnetpagerdesigner )),Toolboxdata ("<{0}: webcustomcontrolpager runat = server ></ {0}: webcustomcontrolpager>")]
The red part above indicates that this control supports editing in design mode.
Step 2:
AspnetpagerdesignerClass
Inherit controldesigner
ControldesignerThe base class of the Web Server Control designer. by inheriting this class, you can implement the design timeliness required. If you want to inherit controls like label.
Code
[Supportspreviewcontrol ( True )]
Public Class Aspnetpagerdesigner: controldesigner
{
Private Designerautoformatcollection _ dafc;
Public Override Designerautoformatcollection autoformats
{
Get
{
If (_ Dafc = Null )
{
_ Dafc = New Designerautoformatcollection ();
_ Dafc. Add ( New Aspnetpagerautoformat ( " English style " ));
_ Dafc. Add ( New Aspnetpagerautoformat ( " Chinese Style " ));
}
Return _ Dafc;
}
}
}
Class:Aspnetpagerautoformat: designerautoformat
Inherits the designerautoformat class, overwrites the apply (Control) method, and implements two styles.
Code
Public Class Aspnetpagerautoformat: designerautoformat
{
Public Aspnetpagerautoformat ( String Name ): Base (Name) {}
Public Override Void Apply (Control)
{
If (Control Is Webcustomcontrolpager)
{
Webcustomcontrolpager aspnetpager = (Webcustomcontrolpager) control;
If ( This . Name = " English style " )
{
Aspnetpager. gofirsttext = " First " ;
Aspnetpager. prevpagetext = " Prev " ;
Aspnetpager. nextpagetext = " Next " ;
Aspnetpager. lastpagetext = " Last " ;
Aspnetpager. sgotext = " Go " ;
Aspnetpager. srecordcounttext = " Total: " ;
Aspnetpager. irowscount = 10 ;
Aspnetpager. irecordcount = 150 ;
}
Else If ( This . Name = " Chinese Style " )
{
Aspnetpager. gofirsttext = " Homepage " ;
Aspnetpager. prevpagetext = " & Lt; Previous Page " ;
Aspnetpager. nextpagetext = " Next Page & gt; " ;
Aspnetpager. lastpagetext = " Last page " ;
Aspnetpager. sgotext = " Jump " ;
Aspnetpager. irowscount = 10 ;
Aspnetpager. irecordcount = 150 ;
Aspnetpager. currentpagetext = " Current page: " ;
Aspnetpager. srecordcounttext = " Total number of records: " ;
}
Else
{
Aspnetpager. gofirsttext = " Homepage " ;
Aspnetpager. prevpagetext = " & Lt; Previous Page " ;
Aspnetpager. nextpagetext = " Next Page & gt; " ;
Aspnetpager. lastpagetext = " Last page " ;
Aspnetpager. sgotext = " Jump " ;
Aspnetpager. irowscount = 10 ;
Aspnetpager. irecordcount = 150 ;
Aspnetpager. currentpagetext = " Current page: " ;
Aspnetpager. srecordcounttext = " Total number of records: " ;
}
}
Else
{
Throw NewException ("The method or operation is not implemented.");
}
}