ASP.NET的Repeater如何实现翻页功能?
查到一些代码,但是看不懂,有没有更简单的方法。<formid="Form1"name="form1"method="POST"runat="server"><divsty...
查到一些代码,但是看不懂,有没有更简单的方法。
<form id="Form1" name="form1" method="POST" runat="server">
<div style="padding:5px;background-color:#dedede">
<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>
<hr size="1" color="#000099"/>
<asp:Repeater ID="Repeater1" runat="server">
<Itemtemplate>
<div style="padding:5px;background-color:#dedede">
<%# DataBinder.Eval(Container.DataItem, "Id") %>
</div>
</Itemtemplate>
</asp:Repeater>
</form>
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = DbHelperSQL.Query("select * from fuzi");
PagedDataSource objPds = new PagedDataSource();
objPds.DataSource = ds.Tables[0].DefaultView;
objPds.AllowPaging = true;
objPds.PageSize = 5;
int CurPage;
if (Request.QueryString["Page"] != null)
CurPage=Convert.ToInt32(Request.QueryString["Page"]);
else
CurPage=1;
objPds.CurrentPageIndex = CurPage-1;
lblCurrentPage.Text = "当前页:" + CurPage.ToString();
if (!objPds.IsFirstPage)
lnkPrev.NavigateUrl=Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage-1);
if (!objPds.IsLastPage)
lnkNext.NavigateUrl=Request.CurrentExecutionFilePath+ "?Page=" + Convert.ToString(CurPage+1);
Repeater1.DataSource=objPds;
Repeater1.DataBind();
} 展开
<form id="Form1" name="form1" method="POST" runat="server">
<div style="padding:5px;background-color:#dedede">
<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>
<hr size="1" color="#000099"/>
<asp:Repeater ID="Repeater1" runat="server">
<Itemtemplate>
<div style="padding:5px;background-color:#dedede">
<%# DataBinder.Eval(Container.DataItem, "Id") %>
</div>
</Itemtemplate>
</asp:Repeater>
</form>
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = DbHelperSQL.Query("select * from fuzi");
PagedDataSource objPds = new PagedDataSource();
objPds.DataSource = ds.Tables[0].DefaultView;
objPds.AllowPaging = true;
objPds.PageSize = 5;
int CurPage;
if (Request.QueryString["Page"] != null)
CurPage=Convert.ToInt32(Request.QueryString["Page"]);
else
CurPage=1;
objPds.CurrentPageIndex = CurPage-1;
lblCurrentPage.Text = "当前页:" + CurPage.ToString();
if (!objPds.IsFirstPage)
lnkPrev.NavigateUrl=Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage-1);
if (!objPds.IsLastPage)
lnkNext.NavigateUrl=Request.CurrentExecutionFilePath+ "?Page=" + Convert.ToString(CurPage+1);
Repeater1.DataSource=objPds;
Repeater1.DataBind();
} 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询