分页解决方案 之 QuickPager的使用方法(PostBack分页、自动获取数据)

本文介绍了一个适用于网站后台管理等场景的快速分页组件QuickPager_SQL的使用方法,该组件能够简化分页操作并方便地实现查询及保存查询条件等功能。

 

      适用范围:网站后台管理、OA、CRM、CMS等,从关系型数据库里提取数据,愿意使用Pager_SQL、DataAccessLibrary的情况。

      最佳数据库:MS SQL。

      优点:只需要设置几个属性即可,不用编写“分页事件”的处理代码。可以很方便的实现查询功能,以及保存查询条件。

      Demo下载:http://www.cnblogs.com/jyk/archive/2008/07/29/1255891.html

      使用方法:

      

using  JYK.Data;
using  JYK.Controls;
using  JYK.Controls.Pager;

namespace  JYK.Manage.Help.QuickPager
ExpandedBlockStart.gifContractedBlock.gif
{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
    
/// PostBack分页方式、自定义提取数据的使用方法 
    
/// </summary>

    public partial class postback01 : System.Web.UI.Page
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        
protected override void OnInit(EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
base.OnInit(e);

            
//数据访问函数库的实例
            DataAccessLibrary dal = DALFactory.CreateDAL();
            Pager1.DAL 
= dal;

            
//定义QuickPager_SQL,设置Page属性
            Pager1.PagerSQL.Page = this;

            
//设置显示数据的控件
            Pager1.ShowDataControl = this.GV;


        }


        
protected void Page_Load(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
if (!Page.IsPostBack)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                SetPagerInfo();         
//设置表名、字段名等
            }


        }


ContractedSubBlock.gifExpandedSubBlockStart.gif        
给QuickPager_SQL 设置属性,以便拼接SQL#region 给QuickPager_SQL 设置属性,以便拼接SQL
        
private void SetPagerInfo()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            Pager1.PagerSQL.TableName 
= "News_NewsInfo";          //表名或者视图名称
            Pager1.PagerSQL.TableShowColumns = "*";               //需要显示的字段
            Pager1.PagerSQL.TableIDColumn = "NewsID";             //主键名称,不支持复合主键
            Pager1.PagerSQL.TableOrderByColumns = "NewsID"//排序字段,根据分页算法而定,可以支持多个排序字段
            Pager1.PagerSQL.TableQuery = "";                      //查询条件

            Pager1.PageSize 
= 4;                                        //一页显示的记录数

            
//设置分页方式
            Pager1.PagerSQL.SetPagerSQLKind = PagerSQLKind.MaxMin;


        }

        
#endregion


ContractedSubBlock.gifExpandedSubBlockStart.gif        
在拼接SQL和提取数据、自动绑定控件之前触发,#region 在拼接SQL和提取数据、自动绑定控件之前触发,
        
protected void Pager1_PageChanged(object sender, JYK.Controls.Pager.PageArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
//在拼接SQL和提取数据、自动绑定控件之前触发,
            Response.Write("绑定前<BR>");
        }

        
#endregion


ContractedSubBlock.gifExpandedSubBlockStart.gif        
在自动绑定控件之后触发,#region 在自动绑定控件之后触发,
        
protected void Pager1_GridBinded(object sender, JYK.Controls.Pager.PageArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
//在自动绑定控件之后触发
            
//计算时间
            Response.Write("绑定后,使用的SQL语句:");
            Response.Write(Pager1.PagerSQL.GetSQLByPageIndex(Pager1.PageIndex));               
//测试用
        }

        
#endregion


ContractedSubBlock.gifExpandedSubBlockStart.gif        
处理查询数据的情况#region 处理查询数据的情况
        
protected void Btn_Search_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
//获取查询条件
            string query = "";
            
string tmp = "";

            tmp 
= this.Txt_Title.TextTrimNone;
            
if (tmp.Length > 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
if (query.Length == 0)
                    query 
= " title like '%" + tmp + "%'";
                
else
                    query 
+= " and title like '%" + tmp + "%'";

            }


            
//还可以添加其他的查询条件,这里省略

            
//给QuickPager_SQL 设置查询条件
            this.Pager1.PagerSQL.TableQuery = query;
            
//重新拼接SQL语句
            this.Pager1.PagerSQL.CreateSQL();
            
//绑定控件,显示第一页的数据
            this.Pager1.BindFirstPage();

        }

        
#endregion


ContractedSubBlock.gifExpandedSubBlockStart.gif        
添加后重新显示数据#region 添加后重新显示数据
        
protected void Btn_Add_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
//添加新的数据后,显示第一页的数据
            this.Pager1.BindFirstPage();
        }

        
#endregion


ContractedSubBlock.gifExpandedSubBlockStart.gif        
修改数据后重新显示当前页的数据#region 修改数据后重新显示当前页的数据
        
protected void Btn_Mod_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
//比如在第三页修改了一条数据,修改完毕后,重新显示第三页的数据。
            this.Pager1.BindThisPage();
        }

        
#endregion


ContractedSubBlock.gifExpandedSubBlockStart.gif        
添加后重新显示数据#region 添加后重新显示数据
        
protected void Btn_Del_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
//比如在第三页删除了一条数据后,重新显示第三页的数据。
            
//和修改数据后重新显示的区别在于,删除数据后需要重新统计总记录数,和总页数
            this.Pager1.BindThisPageForDelete();
        }

        
#endregion

    }

}

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值