zoukankan      html  css  js  c++  java
  • <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);
    }
    }

    }

  • 相关阅读:
    “”开天眼“”,天地分割效果
    关于获得当前的index的方法
    echart(2),模拟数据导入篇
    腾讯windows系统服务器
    elsarticle模板 去掉Preprint submitted to
    elsarticle模板 去掉摘要前后的两条横线
    LeetCode 345. Reverse Vowels of a String
    path变量修改后无法保存
    LeetCode 13: Roman to Integer
    LeetCode 118. Pascal's Triangle
  • 原文地址:https://www.cnblogs.com/YoungPop-Chen/p/3391885.html
Copyright © 2011-2022 走看看