SqlPager分页控件的使用!

SqlPager分页控件是一个多功能灵活的分页控件,原理是利用了PagedDataSource()数据源进行分页处理,现此控件已集成于Winson.Framework框架里(以下简称WF),同时也使用了WF框架里的数据库低层操作语句,因此同时也可以支持多种数据库

一、主要功能:
1、支持AJAX分页,也可设置后台Post模式
2、支持多种分页按钮样式,同时也可以自定义按钮样式
3、支持一次性读取所有数据,或者只读取当前页面数据进行分页
4、可对GridView、Repeater、BaseDataList、ListControl等数据源控件进行绑定处理
5、支持直接在页面写SQL语句读取数据,或者在后台设置自定义数据源进行绑定
6、可对分页数据指定排序字段
7、完全开源,可灵活修改,呵呵


二、基本使用:
1、新在页面顶部插入以下代码:

ExpandedBlockStart.gif ContractedBlock.gif <% dot.gif @ Register Assembly="Winson.WControls" Namespace="Winson.SqlPager" TagPrefix="SqlPager"  %>

2、在需要放置分页控件的地方,插入以下代码:

None.gif < SqlPager:SqlPager  ID ="SqlPager1"  runat ="server"  ControlToPaginate ="GridView1"  Width ="700"
None.gif                ItemsPerPage
="4"  BorderStyle =Dotted  BackColor ="#ffffff"  PagerStyle =CustomAndNumeric
None.gif                
FirstButton ="第一页"   PrveButton ="上一页"  NextButton ="下一页"  LastButton ="最后一页"
None.gif                PagingMode
="Cached"   ></ SqlPager:SqlPager >

基本参数说明:
ID:即本分页控件的自身ID
ControlToPaginate:分页控件需绑定的数据源控件的ID,本例中数据源控件为GridView
BorderStyle:分页控件边框样式,本例中为虚线
PagerStyle:即分页按钮的样式,此为一个枚举参数,同时也是设置是否使用AJAX的参数,以下将会有详细说明
PagingMode:是否使用Cached,如果使用NonCached则只读取对当前页面数据,如为Cached,则一次性读取所有数据然后进行分页,建议数据量少时使用NonCached,但如果想与Tab控件配合使用,则必须要使用Cached模式

以下为分页按钮的自定义样式,只有当PagerStyle设置为自定义样式时才生效
FirstButton:第一页的按钮样式
PrveButton:上一页的按钮样式
NextButton:下一页的按钮样式
LastButton:最后一页的按钮样式


3、以上代码配置好后,即可在后台为分页控件设置数据源,当然在前台也可以直接用参数设置

设置数据源有2种方式,一种是直接在前台使用SelectCommand参数进行设置,如将以下语句直接加到控件标签里

None.gif < SqlPager:SqlPager   SelectCommand  = "select * from Employees"   ></ SqlPager:SqlPager >

另一种方式是可以使用自定义的数据源,如DataSet,但在使用自定义数据源之前,需将参数UseCustomDataSource设置为true,如下代码:

None.gif SqlPager1.UseCustomDataSource  =   true ;
None.gif            SqlPager1.CustomDataSource 
=  DBOP.ExecuteDataset( " select * from Employees  " " ds " );
None.gif            SqlPager1.DataBind();

以上方式只能在后台执行。需要注意的是,不管哪种方式,最后都必须在后台调用DataBind()方法。

四、高级应用

1、使用AJAX分页:
  本控件支持AJAX分页,但还必须写一些客户端的代码,相关的客户端代码我已在DEMO里有啦,具体可以打开PagerDemo.aspx文件查看,在需要分页的页面上添加以下JS代码:

None.gif function setPageTo(pageIndex)
ExpandedBlockStart.gifContractedBlock.gif      
dot.gif {
InBlock.gif        var context
=document.getElementById("listDIV");
InBlock.gif        context.innerHTML
="数据加载中dot.gif";
InBlock.gif        var arg
=pageIndex;
InBlock.gif        
<%= ClientScript.GetCallbackEventReference(this"arg""onCallServerComplete""context")%>
ExpandedBlockEnd.gif      }

None.gif
None.gif      function onCallServerComplete(result,context)
ExpandedBlockStart.gifContractedBlock.gif      
dot.gif {
InBlock.gif        context.innerHTML
=result;
ExpandedBlockEnd.gif      }

然后在后台添加相应的AJAX方法,建议使用我DEMO里的方式,将这些代码添加到一个基类页面里,然后各页面继承来用,请看我的BasePage.cs文件,即以下代码:

ContractedBlock.gif ExpandedBlockStart.gif Ajax分页处理 #region Ajax分页处理
InBlock.gif    
//引发回调事件处理
InBlock.gif
    public void RaiseCallbackEvent(string eventArgument)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        serverReturn 
= eventArgument;
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
//回传回调结果
InBlock.gif
    public string GetCallbackResult()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
return PageChange(serverReturn);
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//**//**//// <summary>
InBlock.gif    
/// 执行分页操作
InBlock.gif    
/// </summary>
InBlock.gif    
/// <param name="newIndex">新页面的索引</param>
ExpandedSubBlockEnd.gif    
/// <returns>需显示的页面数据</returns>

InBlock.gif    private string PageChange(string newIndex)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
int newPageIndex = int.Parse(newIndex);
InBlock.gif        SqlPagerBase.GoToPage(newPageIndex);
InBlock.gif        
return GetRenderCode();
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//**//**//// <summary>
InBlock.gif    
/// 将读取的数据呈现在客户端
InBlock.gif    
/// </summary>
ExpandedSubBlockEnd.gif    
/// <returns></returns>

InBlock.gif    private string GetRenderCode()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        StringWriter writer1 
= new StringWriter(System.Globalization.CultureInfo.InvariantCulture);
InBlock.gif        HtmlTextWriter writer2 
= new HtmlTextWriter(writer1);
InBlock.gif
InBlock.gif        
if (GridViewBase != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            GridViewBase.Visible 
= true;
InBlock.gif            GridViewBase.RenderControl(writer2);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else if (RepeaterBase != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            RepeaterBase.Visible 
= true;
InBlock.gif            RepeaterBase.RenderControl(writer2);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else if (DataListBase != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DataListBase.Visible 
= true;
InBlock.gif            DataListBase.RenderControl(writer2);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else if (ListBase != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ListBase.Visible 
= true;
InBlock.gif            ListBase.RenderControl(writer2);
ExpandedSubBlockEnd.gif        }

InBlock.gif        SqlPagerBase.RenderControl(writer2);
InBlock.gif        writer2.Flush();
InBlock.gif        writer2.Close();
InBlock.gif        
return writer1.ToString();
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif    
#endregion

注意,如果你要将以上代码放到独立页面,必须要先继承System.Web.UI.ICallbackEventHandler接口!

编写完以上代码后,再需将SqlPager里的PagerStyle属性设置为以Ajax开头的类型,以下是PagerStyle属性各参数的说明:

ExpandedBlockStart.gif ContractedBlock.gif    ** /**/ ///<summary>
InBlock.gif    
/// 页面样式设置
ExpandedBlockEnd.gif    
/// </summary>

None.gif      public   enum  PagerStyle
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**//**//// <summary>
InBlock.gif        
/// 按钮样式为上下页箭头
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        NextPrev,
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**//**//// <summary>
InBlock.gif        
/// 按钮样式来下拉框页码
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        NumericPages,
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**//**//// <summary>
InBlock.gif        
/// 按钮和下拉框页码一起显示
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        NextAndNumeric,
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**//**//// <summary>
InBlock.gif        
/// 自定义样式,可自定文本
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        CustomStyle,
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**//**//// <summary>
InBlock.gif        
/// 自定义样式,可自定文本,同时显示下拉页码
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        CustomAndNumeric,
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**//**//// <summary>
InBlock.gif        
/// 无刷新箭头式按钮
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        AjaxNext,
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**//**//// <summary>
InBlock.gif        
/// 无刷新箭头式按钮加下拉页码
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        AjaxNextAndNum,
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**//**//// <summary>
InBlock.gif        
/// 无刷新下拉框按钮
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        AjaxNumeric,
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**//**//// <summary>
InBlock.gif        
/// 自定义无刷新分页
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        AjaxCustomPages,
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**//**//// <summary>
InBlock.gif        
/// 自定义无刷新和下拉框页码
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        AjaxCustomAndNumeric
ExpandedBlockEnd.gif    }

2、配合TabControls使用:
  TabControls控件是从Discuz!DNT论坛里抽取出来的,感觉效果挺好,呵,就是类似一个Tab的效果,可以相互切换各自内容,而且此控件里可放任何其他控件或者代码,只是如果放其他的数据源控件,会有些问题,子控件的一些事件会触发不了,具体我也不知道什么原因:(

  同样,当时将此分页控件加到Tab里时,也出现了不少问题,不过现在已修复好这些问题了,但如需与Tab配合使用,现也只能使用AJAX模式!

  如需在Tab下使用SqlPager控件,只需设置以下2个参数后即可以了

None.gif UseTabPager = " true "
None.gifPagingMode
= " NonCached "

至于其他更多参数设置,请自行查看WF类库文档,均有说明了

WF框架下载:
http://bbs.szblogs.com/showtopic-137.html

如不想注册,可到此帖查看详情下载
http://www.cnblogs.com/winsonet/archive/2007/07/31/838253.html

转载于:https://www.cnblogs.com/winsonet/archive/2007/08/05/844075.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值