关于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>
<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 (Pager.StartRecordIndex == Pager.EndRecordIndex && Pager.StartRecordIndex > 1)
BindLastCautionInfo(Pager.StartRecordIndex - Pager.PageSize, Pager.RecordCount - 1);
else
BindLastCautionInfo(Pager.StartRecordIndex, Pager.EndRecordIndex - 1);
先判断执行删除操作后需要绑定的数据第一行与最后一行是否相等.相等刚该页为空.在第一行不为第一页第一行的情况下,绑定上页数据.否则正常绑定数据.
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();
}
{
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();
}
执行删除操作后翻页:{
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);
作者:Bober Song
出处:http://bober.cnblogs.com/
CARE健康网: http://www.aicareyou.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
出处:http://bober.cnblogs.com/
CARE健康网: http://www.aicareyou.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

浙公网安备 33010602011771号