ORACLE自定义分页处理

来源:互联网 发布:淘宝站外活动网站 编辑:程序博客网 时间:2024/05/16 15:05
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="UCPaginationDG.ascx.cs" Inherits="XHQ.HbKyHR.WebHbKyHR.UserControl.UCPaginationDG" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<table cellSpacing="1" cellPadding="0" width="100%" bgColor="#ffa553" border="0">
    
<tr align="left" bgColor="#ffdbbb">
        
<td colSpan="2" height="22" vAlign="bottom">
            
<asp:label id="lblRecordsCount" runat="server">0</asp:label>条 分
            
<asp:label id="lblPageCount" runat="server">0</asp:label>页 当前第
            
<asp:label id="lblCurrPage" runat="server">1</asp:label>
            
<asp:ImageButton id="imgBtn_FirstPage" runat="server" ImageUrl="../Images/fy1.gif" CausesValidation="False"
                CommandName
="First" OnCommand="Page_OnClick"></asp:ImageButton>
            
<asp:linkbutton id="ctrl_PrevPage" runat="server" OnCommand="Page_OnClick" CausesValidation="False"
                CommandName
="prev">上一页</asp:linkbutton>&nbsp;<asp:linkbutton id="ctrl_NextPage" runat="server" OnCommand="Page_OnClick" CausesValidation="False"
                CommandName
="next">下一页</asp:linkbutton>
            
<asp:ImageButton id="imgBtn_LastPage" runat="server" ImageUrl="../Images/fy2.gif" CausesValidation="False"
                CommandName
="Last" OnCommand="Page_OnClick"></asp:ImageButton>
            转到
            
<asp:textbox id="txtToPage" runat="server" Width="25px" CssClass="InputCss" MaxLength="4"></asp:textbox>
            
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ErrorMessage="请填写跳转得页码" Display="Dynamic"
                ControlToValidate
="txtToPage"></asp:RequiredFieldValidator>
            
<asp:regularexpressionvalidator id="RegularExpressionValidator1" ErrorMessage="跳转页码必须为正整数" Display="Dynamic" ValidationExpression="^[1-9]{1,3}"
                ControlToValidate
="txtToPage" Runat="server"></asp:regularexpressionvalidator>&nbsp;
            
<asp:ImageButton id="imgBtnSubmitPage" runat="server" ImageAlign="Bottom" ImageUrl="../Images/go.gif"></asp:ImageButton>
        
</td>
    
</tr>
</table>

namespace UserControl
{
    
using System;
    
using System.Data;
    
using System.Drawing;
    
using System.Web;
    
using System.Web.UI.WebControls;
    
using System.Web.UI.HtmlControls;
    
using XHQ.HbKyHR.MyComponet.DycnamicalSystem;

    
/// <summary>
    
/// UCPaginationDG 的摘要说明。
    
/// </summary>

    public class UCPaginationDG : System.Web.UI.UserControl
    
{
        
protected System.Web.UI.WebControls.LinkButton ctrl_PrevPage;
        
protected System.Web.UI.WebControls.LinkButton ctrl_NextPage;
        
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;

        
//查询数据参数
        private string _sourceid;  //数据源表
        private int _dbNameid;     //数据类型ID
        private int _sysid;        //所属系统ID
        private string _condition; //查询条件

        
//翻页所需参数
        private DataSet _dataSource;            //绑定数据源
        private System.Web.UI.Control _ctrlData;//需要绑定得控件
        private int _pageNo = 1;                //当前页码
        private int _pageSize = 15;                //分页大小
        private int _recordCount = 0;           //记录条数
        protected System.Web.UI.WebControls.Label lblRecordsCount; //总得记录数
        protected System.Web.UI.WebControls.Label lblPageCount;    //总得页数
        protected System.Web.UI.WebControls.Label lblCurrPage;     //当前页码
        private bool _isAllDisplay = true//是否显示全部列
        protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
        
protected System.Web.UI.WebControls.TextBox txtToPage;
        
protected System.Web.UI.WebControls.ImageButton imgBtnSubmitPage;
        
protected System.Web.UI.WebControls.ImageButton imgBtn_LastPage;
        
protected System.Web.UI.WebControls.ImageButton imgBtn_FirstPage; //是否显示全部列
        private bool _isConvertColName = true//是否转换列名

        
翻页控件属性集合

        
private void Page_Load(object sender, System.EventArgs e)
        
{
            
if(!this.IsPostBack)
            
{
                
//初始化页码值
                ViewState["CurrentPage"= _pageNo;
                
//第一绑定值
                BindDataToControl();
            }

        }


        
绑定数据到指定的控件:DataGrid,DataList,Repeater

        
取得绑定的数据源,并设置页面分页属性

        
自定义翻页事件(上一页,下一页事件)

        
Web 窗体设计器生成的代码

        
private void imgBtnSubmitPage_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        
{
            
//跳转页
            int iPageNo = Convert.ToInt32(txtToPage.Text);
            
this.ViewState["CurrentPage"= iPageNo;

            BindDataToControl();
        }

    }

}

存储过程:

  PROCEDURE p_pagequery (
    p_pagesize               INT,   --每页记录数
    p_pageno                 INT,   --当前页码,从 1 开始
    p_sqlselect              VARCHAR2,   --查询语句,含排序部分
    p_selcolumn              VARCHAR2,   --查询列信息
    p_sqlcount               VARCHAR2,   --获取记录总数的查询语句
    p_outrecordcount   OUT   INT,   --返回总记录数
    cur_out            OUT   pkg_admin.T_RefCursor
  )
  IS
/*********************************************************************
    1.  名称     【p_pagequery】
    2.  用途        B/S, C/S 分页查询
    3.  版本
         版本号     日期            执行人    日志记录           当前状态
         ---------------------------------------------------------------------------
            1>     
            2>    
    4.  备注

**********************************************************************/
    v_sql         VARCHAR2 (3000);
    v_count       INT;
    v_heirownum   INT;
    v_lowrownum   INT;
  BEGIN
    ----取记录总数
    EXECUTE IMMEDIATE p_sqlcount
                 INTO v_count;

    p_outrecordcount := v_count;
    ----执行分页查询
    v_heirownum := p_pageno * p_pagesize;
    v_lowrownum := v_heirownum - p_pagesize + 1;
    v_sql :=
         'SELECT '
      || p_selcolumn
      || '
            FROM (
                  SELECT A.*, rownum rn
                  FROM  ('
      || p_sqlselect
      || ') A
                  WHERE rownum <= '
      || TO_CHAR (v_heirownum)
      || '
                 ) B
            WHERE rn >= '
      || TO_CHAR (v_lowrownum);
    DBMS_OUTPUT.put_line (v_sql);
    OPEN cur_out FOR v_sql;
  END p_pagequery;

 

原创粉丝点击