<asp:Panel + PagedDataSource 实现 分页 (小数据量)
<asp:Panel runat="server" ID="pagepanel" Width="501px">
<asp:Label runat="server" ID="countlabel"></asp:Label>
<asp:Label runat="server" ID="currentlabel"></asp:Label>
<asp:HyperLink runat="server" ID="firstlinkbutton" Text="首页"></asp:HyperLink>
<asp:HyperLink runat="server" ID="prevlinkbutton" Text="上一页"></asp:HyperLink>
<asp:HyperLink runat="server" ID="newlinkbutton" Text="下一页"></asp:HyperLink>
<asp:HyperLink runat="server" ID="lastlinkbutton" Text="尾页"></asp:HyperLink>
转到<asp:TextBox ID="TextBox1" runat="server" Width="19px"></asp:TextBox>页
<asp:Button ID="Button1" runat="server" Text="Go" OnClick="Button1_Click" />
</asp:Panel>
<asp:HiddenField ID="HiddenField1" runat="server" />
private void PageDatasource()
{
DataTable dt = PERReport.Instance.GetPerReportStateInfoByModelsNumber("1813-01-20", "2214-10-29");
if (dt.Rows.Count > 0)
{
this.pagepanel.Visible = true;
PagedDataSource objPds = new PagedDataSource();
objPds.DataSource = dt.DefaultView;
objPds.AllowPaging = true;
objPds.PageSize = 10;
this.HiddenField1.Value = objPds.PageCount.ToString();
this.countlabel.Text = "共:" + objPds.PageCount.ToString() + "页";
int CurPage;
if (Request.QueryString["Page"] != null)
{
CurPage = Convert.ToInt32(Request.QueryString["Page"]);
}
else
{
CurPage = 1;
}
objPds.CurrentPageIndex = CurPage - 1;
this.currentlabel.Text = "当前页:" + CurPage.ToString();
this.TextBox1.Text = CurPage.ToString();
if (!objPds.IsFirstPage)
{
this.firstlinkbutton.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=1";
this.prevlinkbutton.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1);
}
if (!objPds.IsLastPage)
{
this.newlinkbutton.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1);
this.lastlinkbutton.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + objPds.PageCount.ToString();
}
this.GridView_ModelsPerReport.DataSource = objPds;
this.GridView_ModelsPerReport.DataBind();
}
else
{
this.pagepanel.Visible = false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
int CurPage;
int i = Convert.ToInt32(this.HiddenField1.Value);
if (Int32.TryParse(this.TextBox1.Text, out CurPage))
{
if (CurPage < 1 || CurPage > i)
{
Response.Redirect(Request.CurrentExecutionFilePath + "?page=1");
}
else
{
Response.Redirect(Request.CurrentExecutionFilePath + "?page=" + CurPage);
}
}
}
posted on 2013-10-28 10:13 YoungPop_Chen 阅读(160) 评论(0) 编辑 收藏 举报