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

 

 

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

      优点:可以使用自己喜欢的方式获取数据,不仅仅限于关系型数据库,其他的也都可以。

      缺点,要写的代码比较多。

      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 PostBack02 : System.Web.UI.Page
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        
//如果您不使用Pager_SQL和DataAccessLibrary的话,那么就不用下面两行代码了。
        QuickPagerSQL pagerSQL = new QuickPagerSQL();
        
//数据访问函数库的实例
        DataAccessLibrary dal = DALFactory.CreateDAL();

        
protected override void OnInit(EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
base.OnInit(e);
            
            
//设置显示数据的控件
            Pager1.ShowDataControl = this.GV;

            
//设置成自定义的方式获取
            Pager1.GetDataKind = PagerRunKind.Customer;

            pagerSQL.Page 
= this;
           
        }


        
protected void Page_Load(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
if (!Page.IsPostBack)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
//设置QuickPager_SQL的属性
                GetPagerSQL();

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


                
//设置总记录数、总页数
                SetRecprdCount();

                
//获取第一页的记录
                string sql = pagerSQL.GetSQLByPageIndex(1);

                
//数据访问函数库的实例

                GV.DataSource 
= dal.ExecuteFillDataTable(sql);
                GV.DataBind();
            }


        }


ContractedSubBlock.gifExpandedSubBlockStart.gif        
设置QuickPager_SQL的属性#region 设置QuickPager_SQL的属性
        
private void GetPagerSQL()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
//设置QuickPager_SQL的属性
            pagerSQL.Page = this;

            pagerSQL.TableName 
= "News_NewsInfo";          //表名或者视图名称
            pagerSQL.TableShowColumns = "*";               //需要显示的字段
            pagerSQL.TableIDColumn = "NewsID";             //主键名称,不支持复合主键
            pagerSQL.TableOrderByColumns = "NewsID"//排序字段,根据分页算法而定,可以支持多个排序字段
            pagerSQL.TableQuery = "";                      //查询条件

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

            

        }

        
#endregion


ContractedSubBlock.gifExpandedSubBlockStart.gif        
设置总记录数、总页数#region 设置总记录数、总页数
        
private void SetRecprdCount()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            pagerSQL.CreateSQL();

            
//获取总记录数,可以用count(*)统计,也可以使用其他方法获得。
            string AllCount = dal.ExecuteString(pagerSQL.GetRecordCountSQL);
            
if (AllCount != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                pagerSQL.RecordCount 
= int.Parse(AllCount);
            }


            pagerSQL.ComputePageCount();

            Pager1.RecordCount 
= pagerSQL.RecordCount;
            Pager1.PageCount 
= pagerSQL.PageCount;

        }

        
#endregion


ContractedSubBlock.gifExpandedSubBlockStart.gif        
在拼接SQL和提取数据、自动绑定控件之前触发,#region 在拼接SQL和提取数据、自动绑定控件之前触发,
        
protected void Pager1_PageChanged(object sender, JYK.Controls.Pager.PageArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
//您可以使用下面提供的方法获得数据,也可以使用其他的方法获得记录。
            
//e.CurrentPageIndex:想要翻到的页号。
             
            
string sql = pagerSQL.GetSQLByPageIndex(e.CurrentPageIndex );

            GV.DataSource 
= dal.ExecuteFillDataTable(sql);
            GV.DataBind();


            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语句:");
        }

        
#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.pagerSQL.TableQuery = query;
            
//重新拼接SQL语句
            this.pagerSQL.CreateSQL();
            
            
//绑定控件,显示第一页的数据
            string sql = pagerSQL.GetSQLByPageIndex(1);

            GV.DataSource 
= dal.ExecuteFillDataTable(sql);
            GV.DataBind();

            
//设置总记录数、总页数
            SetRecprdCount();

            
//修改分页控件的UI。
            Pager1.PageIndex = 1;
            Pager1.SetPagerUI();

        }

        
#endregion


    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值