zoukankan      html  css  js  c++  java
  • 利用Request对象的CurrentExecutionFilePath做分页

    CurrentExecutionFilePath的解释上:获取当前请求的虚拟路径。

    见代码:

    后台
    1 protected void Page_Load(object sender, EventArgs e)
    2 {
    3 if (!IsPostBack)
    4 {
    5 databind();
    6 this.HyperLink1.Visible = true;
    7 this.HyperLink4.Visible = true;
    8 }
    9 }
    10 public void databind()
    11 {
    12 SqlConnection con = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=Northwind;Integrated Security=True");
    13 SqlCommand cmd = new SqlCommand("select * from Customers", con);
    14 SqlDataAdapter da = new SqlDataAdapter(cmd);
    15 DataSet ds = new DataSet();
    16 da.Fill(ds);
    17 PagedDataSource ps = new PagedDataSource();
    18 ps.DataSource = ds.Tables[0].DefaultView;
    19 ps.AllowPaging = true;
    20 int pageIndex;
    21 if (Request.QueryString["page"] == null)
    22 {
    23 pageIndex = 0;
    24 }
    25 else
    26 {
    27 pageIndex = Convert.ToInt32(Request.QueryString["page"]);
    28 }
    29 ps.CurrentPageIndex = pageIndex;
    30 this.Label1.Text =Convert.ToString( pageIndex + 1);
    31 this.Label2.Text = ps.PageCount.ToString();
    32 this.HyperLink1.NavigateUrl = Request.CurrentExecutionFilePath + "?page=0";
    33 if (pageIndex <= 0)
    34 {
    35 this.HyperLink2.NavigateUrl = Request.CurrentExecutionFilePath + "?page=0";
    36 }
    37 else
    38 {
    39 this.HyperLink2.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(pageIndex - 1);
    40 }
    41 this.HyperLink4.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(Convert.ToInt32(this.Label2.Text) - 1);
    42 if ((pageIndex+1) >= Convert.ToInt32(this.Label2.Text))
    43
    44 {
    45 this.HyperLink3.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(Convert.ToInt32(this.Label2.Text) - 1);
    46 }
    47 else
    48 {
    49 this.HyperLink3.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(pageIndex + 1);
    50 }
    51 this.GridView1.DataSource = ps;
    52 this.GridView1.DataBind();
    53 }

    前台:

    前台
    1 <div>
    2 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
    3 <Columns>
    4 <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" />
    5 <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" />
    6 <asp:BoundField DataField="ContactName" HeaderText="ContactName" />
    7 <asp:BoundField DataField="ContactTitle" HeaderText="ContactTitle" />
    8 </Columns>
    9 </asp:GridView>
    10 <asp:HyperLink ID="HyperLink1" runat="server">首页</asp:HyperLink>
    11 <asp:HyperLink ID="HyperLink2" runat="server">上一页</asp:HyperLink>
    12 <asp:HyperLink ID="HyperLink3" runat="server">下一页</asp:HyperLink>
    13 <asp:HyperLink ID="HyperLink4" runat="server">尾页</asp:HyperLink>
    14 当前页为:<asp:Label ID="Label1" runat="server" Text="1"></asp:Label>
    15 总共<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
    16 </div>
  • 相关阅读:
    词汇小助手V1.0——一款跨平台词频统计和外语学习工具
    穿越狙击V1.0
    词汇小助手V1.4——加入单词测试功能
    词汇小助手V1.2——可以显示英语单词的国际音标
    词汇小助手官方网站发布了
    强大的云存储与应用管理工具DzzOffice1.0 Beta(大桌子办公)发布下载 大桌子
    <!DOCTYPE>前加有<! xxx >注释在IE中引发的bug
    去笔试腾讯的前端实习生,题目太尼玛坑爹了
    IE中的布局BUG和一些可以避开的BUG
    removeClass,addClass的原生JS代码
  • 原文地址:https://www.cnblogs.com/hfliyi/p/2044082.html
Copyright © 2011-2022 走看看