Repeater paging (Oracle generic paging Stored Procedure Combined with AspNetPage) (original)

Source: Internet
Author: User
Tags dbase psql

Paging is one of the common functions in development, especially the Repeater paging, which collects some information and finds that the Repeater paging is usually divided into two types.

1. False paging (PagedDataSource implementation) 2. Real paging. This article focuses on the latter. Although I use. net and oracle as examples

Sub. In fact, the implementation methods of other platforms are similar.

1. Writing stored procedures

View Code

-- Define a package to return the total number of pages and the current number of pages to prepare for the paging Stored Procedure
Create or replace package pck_page is

Type T_Page is ref cursor; -- defines the cursor variable used to return the record set

Procedure getpagerecord (
Pindex in number, -- paging Index
Psql in varchar2, -- SQL statement that generates dataset
Psize in number, -- page size
Pcount out number, -- total number of returned pages
V_cur out T_Page -- returns the current page data record
);

End pck_page
-- Define the package body
Create or replace package body pck_page is
Procedure getpagerecord (
Pindex in number,
Psql in varchar2,
Psize in number,
Pcount out number,
V_cur out T_Page
)
As

V_ SQL varchar2 (1000 );
V_count number;
V_plow number;
V_phei number;
Begin

V_ SQL: = 'select count (*) from ('| psql | ')';
Execute immediate v_ SQL into v_count;
Pcount: = ceil (v_count/psize );

V_phei: = pindex * psize + psize;
V_plow: = v_phei-psize + 1;
-- Psql: = select rownum rn, t. * from test t; -- The rownum field must be included.
V_ SQL: = 'select * from ('| psql |') where rn between' | v_plow | 'and' | v_phei;

Open v_cur for v_ SQL;

End getpagerecord;

End pck_page;
-- Define a stored procedure to get the total number of records to prepare for the paging Stored Procedure
Create or replace procedure p_app_GetCount (
P_ SQL in varchar2,
P_count out number
)
As

V_ SQL varchar2 (1000 );
V_prcount number;

Begin

V_ SQL: = 'select count (*) from ('| p_ SQL | ')';
Execute immediate v_ SQL into v_prcount;
P_count: = v_prcount; -- total number of returned records

End p_app_GetCount;

-- Define the paging Stored Procedure
Create or replace procedure p_app_page (
P_pagesql in varchar2, -- the SQL statement that generates paging must contain the rownum Field and Its alias is rn. For example: select rownum rn, t. * from test t
P_pagesize in number, -- number of entries displayed on each page
P_pageindex in number, -- the index of the displayed page starts from 0.
P_totalcount out number, -- total number of items
P_pagecount out number, -- total number of pages
P_currentpagedata out pck_page.T_Page -- return the data on the current page.
)
As
Begin
Pck_page.getpagerecord (p_pageindex, p_pagesql, p_pagesize, p_pagecount, p_currentpagedata );
P_app_getcount (p_pagesql, p_totalcount );
End;

2. AspNetPage and Repeater

View Code

AspNetPage registration:
<% @ Register Assembly = "AspNetPager" Namespace = "Wuqi. Webdiyer" TagPrefix = "webdiyer" %>
AspNetPage placement:
<Webdiyer: AspNetPager ID = "AspNetPager1" runat = "server" AlwaysShow = "True" CustomInfoHTML = "% CurrentPageIndex % PAGE % RecordCount % records"
FirstPageText = "Homepage" LastPageText = "last" NextPageText =
"Next page" PrevPageText = "Previous Page" ShowCustomInfoSection = "Right"
ShowPageIndexBox = "Never" SubmitButtonText = "Go" TextAfterPageIndexBox = "page" OnPageChanged =
"AspNetPager1_PagChanged" CurrentPageButtonPosition = "Center" CustomInfoSectionWidth = "45%" CustomInfoTextAlign = "Center"
PageSize = "10" ShowPageIndex = "False" Width = "18%" PagingButtonLayoutType = "Span" PagingButtonSpacing = "1px">
</Webdiyer: AspNetPager>
Repeater:
<Asp: Repeater ID = "rptInStorageHistory" runat = "server">
<HeaderTemplate>
<Table border = "0" style = "width: 100% ;"
Class = "TableStyle">
<Tr id = "TableTitle" align = "center" valign = "middle">
<Td width = "2%" style = "border-left: 0px solid
#000; ">
& Nbsp;
</Td>
& Lt; td width = "11%" & gt;
Transaction No.
</Td>
& Lt; td width = "11%" & gt;
Name
</Td>
& Lt; td width = "12%" & gt;
Type
</Td>
</Tr>
</HeaderTemplate>
<ItemTemplate>
<Tr align = "center" valign = "middle" class = "TableDetail2">
<Td width = "2%" style = "border-left: 0px solid #000;">
& Nbsp;
</Td>
& Lt; td width = "12%" & gt;
<% # Eval ("id") %>
</Td>
& Lt; td width = "12%" & gt;
<% # Eval ("name") %>
</Td>
& Lt; td width = "12%" & gt;
<% # Eval ("name") %>
</Td>
</Tr>
</ItemTemplate>
<FooterTemplate>
</Table>
</FooterTemplate>
</Asp: Repeater>

3. Call Test

View Code

-- Call the paging stored procedure to obtain the total number of pages and the current number of pages.
Public DataTable GetPageRecord (MPage page, out ArrayList result)
{
OracleParameter [] oracleparameter = new OracleParameter [6];
Oracleparameter [0] = new OracleParameter ("p_pagesql", OracleDbType. Varchar2, ParameterDirection. Input );
Oracleparameter [0]. Value = page. pagesql;
Oracleparameter [1] = new OracleParameter ("p_pagesize", OracleDbType. Decimal, ParameterDirection. Input );
Oracleparameter [1]. Value = page. pagesize;
Oracleparameter [2] = new OracleParameter ("p_pageindex", OracleDbType. Decimal, ParameterDirection. Input );
Oracleparameter [2]. Value = page. pageindex;
Oracleparameter [3] = new OracleParameter ("p_totalcount", OracleDbType. Decimal, ParameterDirection. Output );
Oracleparameter [4] = new OracleParameter ("p_pagecount", OracleDbType. Decimal, ParameterDirection. Output );
Oracleparameter [5] = new OracleParameter ("p_currentpagedata", OracleDbType. RefCursor, ParameterDirection. Output );
Return dataaccess. ExecuteProcedureWithTable (ref oracleparameter, "p_app_page", out result );

}
-- Bind Repeater
/// <Summary>
/// Pagination control downloaded from the internet
/// </Summary>
/// <Param name = "aspnetpager"> page control AspNetPager </param>
/// <Param name = "pagesql"> Add the rownum column in SQL and use the alias rn. For example, select t. *, rownum rn from asset_fa_stock t </param>
Public void BindingRepeaterWithAspnetpager (AspNetPager aspnetpager, Repeater bindingtarget, String pagesql)
{
DCommonBase dbase = null;
Int recordcount = 0;
MPage page = null;
ArrayList result = null;
Page = new MPage ();
Dbase = new DCommonBase ();
Page. pagesize = aspnetpager. PageSize;
Page. pageindex = aspnetpager. StartRecordIndex/aspnetpager. PageSize;
Page. pagesql = pagesql;
Bindingtarget. DataSource = dbase. GetPageRecord (page, out result );
Bindingtarget. DataBind ();
If (result! = Null & result. Count> 0)
{
If (int. TryParse (result [0]. ToString (), out recordcount ))
{
Aspnetpager. RecordCount = recordcount;
}
Else
{
Aspnetpager. RecordCount = 0;
}
}

}
-- Call on the page
Void bindData ()
{
G_assetinstoragemanager.BindingRepeaterWithAspnetpager (AspNetPager1, rptInStorageHistory, "select t. *, rownum rn from stock t ");
}
Protected void AspNetPager1_PageChanged (object sender, EventArgs e)
{
BindData ();

}
Protected void btnPage_Click (object sender, EventArgs e)
{
BindData ();
}

 

Note:

1. For details about how to use AspNetPage, refer to relevant documents.

2. For details about paging, refer to my own article: and Oracle paging (collection and sorting)

Related Article

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.