关于AspNetPager分页控件的使用

在GridView的使用

需要设置AllowPaging和PageSize属性,与AspNetPager的属性对应.

<tr>
<td colspan="2" style="margin-right: 100px; margin-top: 20px; margin-bottom: 20px"
align
="right">
<webdiyer:AspNetPager ID="Pager" AlwaysShow="true" runat="server" Height="22px" OnPageChanged="Pager_PageChanged"
PageSize
="8" FirstPageText="首页" LastPageText="末页" NextPageText="下一页" PrevPageText="上一页">
</webdiyer:AspNetPager>
</td>
</tr>
因为涉及到最尾页最后一条操作特殊情况删除操作,故在绑定数据判断此种情况:
绑定数据:
         if (saledt != null)//DataTable
        {
int iPage = saledt.Rows.Count;
Pager.RecordCount 
= iPage;
salesInfos.DataSource 
= saledt;
showTip.Visible 
= false;
try
{
salesInfos.PageIndex 
= Pager.CurrentPageIndex - 1;
if (Pager.PageCount > 1)
Pager.Visible 
= true;
else
Pager.Visible 
= false;
}
catch (Exception ex)
{
throw (ex);
}
salesInfos.DataBind();
}
[二]在Repeater控件中使用:
if (dt != null)
{
DataTable srcTbl 
= dt.Clone();
DataView dv 
= dt.DefaultView;
int iPage = dt.Rows.Count;
if (iStart == 0 && iEnd == 0)
{
for (int i = 0; i < (iPage > Pager.PageSize - 1 ? Pager.PageSize : iPage); i++)
{
srcTbl.ImportRow(dv[i].Row);
}
}
else
{
for (int i = iStart; i <= iEnd; i++)
{
srcTbl.ImportRow(dv[i 
- 1].Row);
}
}
Pager.RecordCount 
= iPage;

cautions.DataSource 
= srcTbl;
cautions.DataBind();
}
执行删除操作后翻页:

if (Pager.StartRecordIndex == Pager.EndRecordIndex && Pager.StartRecordIndex > 1)
BindLastCautionInfo(Pager.StartRecordIndex 
- Pager.PageSize, Pager.RecordCount - 1);
else
BindLastCautionInfo(Pager.StartRecordIndex, Pager.EndRecordIndex 
- 1);
先判断执行删除操作后需要绑定的数据第一行与最后一行是否相等.相等刚该页为空.在第一行不为第一页第一行的情况下,绑定上页数据.否则正常绑定数据.
posted @ 2008-06-05 14:53  大力哥的技术  阅读(350)  评论(0)    收藏  举报
版权
作者:Bober Song

出处:http://bober.cnblogs.com

Care健康:http://www.aicareyou.com

推荐空间:华夏名网

本文首发博客园,版权归作者跟博客园共有。

转载必须保留本段声明,并在页面显著位置给出本文链接,否则保留追究法律责任的权利。