后台代码
private void fillit()
{
string message = Session["sqlmessage"].ToString();
searchT.Visible = false;
fillrepeater(message);
}
private void fillrepeater(string sqlstring)
{
BLL.Plan_Work bpw = new BLL.Plan_Work();
DataTable ds = bpw.GetList(sqlstring).Tables[0];
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.DefaultView;
pds.AllowPaging = true;
pds.PageSize = 10;
int CPage;
if (Request.QueryString["Page"] != null)
CPage = Convert.ToInt32(Request.QueryString["Page"]);
else
CPage = 1;
pds.CurrentPageIndex = CPage - 1;
lblCurrentPage.Text = "当前页" + CPage.ToString() + "共(" + pds.PageCount + ")页";
if (!pds.IsFirstPage)
{
lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?action=1&Page=" + Convert.ToString(CPage - 1);
}
if (!pds.IsLastPage)
{
lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?action=1&Page=" + Convert.ToString(CPage + 1);
}
showRP.DataSource = pds;
showRP.DataBind();
showD.Visible = true;
}
前台代码
<table>
<asp:Repeater ID="showRP" runat="server">
<HeaderTemplate>
<tr>
<td>
计划名称
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%#DataBinder.Eval(Container.DataItem,"Name") %>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
<div id="showD" runat="server">
<asp:Label ID="lblCurrentPage" runat="server"></asp:Label>
<asp:HyperLink ID="lnkPrev" runat="server">上一页</asp:HyperLink>
<asp:HyperLink ID="lnkNext" runat="server">下一页</asp:HyperLink>
</div>