AspnetPager

页面引用:<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
控件属性:
<webdiyer:AspNetPager ID="AspNetPager1" runat="server"
HorizontalAlign="Right"  //页导航位置
NumericButtonTextFormatString="-{0}-"  //数字格式
ShowFirstLast="False"  //不出现首尾页按钮,对应的有ShowPageIndex数字按钮,ShowPrevNext上/下页
Width="600px"  //控件宽度
ShowBoxThreshold="2"  //当页数达到多少时才出现跳转输入框,ShowInputBox="never"永不出现跳转输入框
PageSize="6" //数据每页显示个数
NumericButtonCount="4"  //导航数字键显示个数
NumericButtonType="Text"  //页码为Text(还有Image)
NavigationButtonType="Image" PagingButtonType="Image"  //首/尾页、上/下一页为Image
ImagePath="~/image" ButtonImageExtension=".jpg"   //图片路径和后缀
ButtonImageNameExtension="g" DisabledButtonImageNameExtension="n" 

//可用/不可用时的文件名最后的字符串(如上一页的图片可用时显示为prevg.jpg,不可用时显示为prevn.jpg。可以不加)
InputBoxClass="text2" TextAfterInputBox="" //跳转页的TextBox样式和后接文字
OnPageChanging="AspNetPager1_PageChanging" />


页面事件:
if (!IsPostBack)
{
    AspNetPager1.RecordCount = GetRecordCount();  //数据行数
    BindData();
}
private void BindData()
{
    ...
    DataSet ds = new DataSet();
    _dataAdapter.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "News");   

  //虽然仅使用所请求的记录来填充目标DataSet,但仍会使用返回整个查询的资源。

  DataList1.DataSource = ds.Tables["News"];
    DataList1.DataBind();
}
protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
    AspNetPager1.CurrentPageIndex = e.NewPageIndex;
    BindData();
}

//BindData的另一种写法:

int rowStart = AspNetPager1.StartRecordIndex;  //如果PageSize为10,则点击第2页触发的绑定事件中,StartRecordIndex为11。

int rowEnd = AspNetPager1.StartRecordIndex + AspNetPager1.PageSize;

DataList1.DataSource = NewsDataBLL.GetPageNews(rowEnd, rowStart); 

Oracle SQL:

SELECT NewsId...
FROM

(  

  SELECT rownum AS oROWINDEX, NewsId...  //定义别名,用于保存此SQL的rownum

  FROM ( SELECT NewsId... FROM NewsTable ORDER BY CreateTime DESC )

  WHERE rownum < :oendIndex

)
WHERE oROWINDEX >= :ostartIndex  //外部调用内嵌字段作条件

 

posted @ 2009-10-26 11:27  DaCHun  阅读(582)  评论(0编辑  收藏  举报