You can write a paging control for the object class to isolate the page number layer from the specific information of the database.

Source: Internet
Author: User

Currently, there are many mature paging controls on the network, but many of them are paging based on SQL statements and directly bound to paging controls. They cannot be bound through entity sets, therefore, it is not very suitable for the architecture development of my current project. I accidentally saw the SQL Server Stored Procedure and the C # paging class published by Mr. "never say goodbye" on my blog to simplify yourCode! Inspired by my use of the architecture, I wrote a paging control.

Paging controls are indispensable in Web development. However, currently, many paging controls are paging by setting SQL statements, the disadvantage of this paging control is that it is closely related to the database. When you need to customize the output content, you need to bind the name of the database field, additionally, You Need To splice SQL statements at the underlying layer for paging controls to call. in a layered architecture, such operations from the interface layer to the underlying database damage the elegance and features of the layered architecture. if you can use the exclusive features (easy-to-use/paging retrieval) of the paging control and the features of the layered architecture (sharing the entity class, isolating the underlying layer and details ), in this way, when the page control is laid out, the object class information is accessed, and page-based data retrieval is available, which can perfectly solve this problem.

I have been hoping to solve this problem in my spare time. through constant exploration and research on paging controls, finally, it better solved some shortcomings of the paging controls used in the current architecture and hoped to be used in future projects. the paging Control performs paging computing through a stored procedure on the database layer. At the data access layer, it calls the stored procedure through code to obtain the number of records or record data, each layer transmits data through the entity class of a paging control to transmit the information required by the paging control.
The effect of the control is as follows: code please download in connection http://www.wuhuacong.com.cn/UpLoadFile/PagerDemo.zip
The attachment contains Stored Procedure scripts by PAGE, control code, control transfer entity, business logic code, and page test code. /**/ ///   <Summary>
/// Queries the database based on conditions and returns an object set (used for displaying paging data)
///   </Summary>
///   <Param name = "condition"> Query Conditions </Param>
///   <Param name = "info"> Paging entity </Param>
///   <Returns> Set of specified objects </Returns>
Protected   Virtual Arraylist basefind ( String Condition, pagerinfo info)
{
Arraylist list =   New Arraylist ();

Pagerhelper helper =   New Pagerhelper (tablename, condition, connectionstring );
Info. recordcount = Helper. getcount ();

Pagerhelper helper2 =   New Pagerhelper (tablename, False , " * " , Primarykey,
Info. pagesize, info. currenetpageindex, False , Condition, connectionstring );

Using (Idatareader Dr = Helper2.getdatareader ())
{
While (Dr. Read ())
{
List. Add (This. Datareadertoentity (DR ));
}
}
Return List;
}

/**/ ///   <Summary>
/// Queries the database based on conditions and returns an object set (used for displaying paging data)
///   </Summary>
///   <Param name = "condition"> Query Conditions </Param>
///   <Param name = "info"> Paging entity </Param>
///   <Returns> Set of specified objects </Returns>
Public Productscollection find ( String Condition, pagerinfo info)
{
Productscollection Products= NewProductscollection ();
Products. addrange (Base. Basefind (condition, Info ));
ReturnProducts;
}

// The page background call code is as follows:
Private   Void Searchdata ()
{
Pagerinfo info=Pager1.pagerinfo;
Pager1.datasource=Product. findbyproductname (This. Txtproductname. Text, Info );
Pager1.pagerinfo=Info;
Pager1.databind ();
}
 
Public   Void Pageindexchanged ( Object Sender, pager. pageindexchangedeventargs E)
{
Searchdata ();
}
Private   Void Btnsearch_click ( Object Sender, system. eventargs E)
{
Pager1.currentpageindex= 1;
Searchdata ();
}

Hope to help you !!

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.