數據庫分頁讀取
阿新 • • 發佈:2017-10-13
logs cli data end quest 上下 nbsp led emp
.aspx
<div align="center"> <asp:Label ID="Label1" runat="server" Text=" 當前頁:"></asp:Label> <asp:Label ID="Label2" runat="server" Text="1"></asp:Label> <asp:Label ID="Label3" runat="server" Text="總頁數:"></asp:Label> <asp:Label ID="Label4" runat="server" Text="Label"></asp:Label> <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">首頁</asp:LinkButton> <asp:LinkButton ID="LinkButton2" runat="server" OnClick="LinkButton2_Click">上一頁</asp:LinkButton> <asp:LinkButton ID="LinkButton3" runat="server" OnClick="LinkButton3_Click">下一頁</asp:LinkButton> <asp:LinkButton ID="LinkButton4" runat="server" OnClick="LinkButton4_Click">末頁</asp:LinkButton> </div>
.cs
public void bindData() { //分頁1 string strinfoType = Request.QueryString["type"]; DataAccess.Da dac= new DataAccess.Da(); //System.Data.DataSet ds = dac.ds_EncyTypeList(); string sql = "select * from Ency_info where Encytype=‘" + strinfoType + "‘ order by infoID desc"; SqlCommand cmd = new SqlCommand(sql, dac.con); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); PagedDataSource pds = new PagedDataSource(); pds.DataSource = ds.Tables[0].DefaultView; pds.AllowPaging = true; pds.PageSize = 20; int currentIndex = Convert.ToInt32(this.Label2.Text) - 1; this.LinkButton1.Enabled = true; this.LinkButton2.Enabled = true; this.LinkButton3.Enabled = true; this.LinkButton4.Enabled = true; pds.CurrentPageIndex = currentIndex; if (currentIndex == 0) { this.LinkButton1.Enabled = false; this.LinkButton2.Enabled = false; } if (currentIndex == pds.PageCount - 1) { this.LinkButton3.Enabled = false; this.LinkButton4.Enabled = false; } this.Label4.Text = pds.PageCount.ToString(); this.GridView1.DataSource = pds; this.GridView1.DataBind(); //分頁1wan } //首頁 上下末頁 protected void LinkButton1_Click(object sender, EventArgs e) { this.Label2.Text = "1"; bindData(); } protected void LinkButton2_Click(object sender, EventArgs e) { int temp = Convert.ToInt32(this.Label2.Text) - 1; this.Label2.Text = temp.ToString(); bindData(); } protected void LinkButton3_Click(object sender, EventArgs e) { int temp = Convert.ToInt32(this.Label2.Text) + 1; this.Label2.Text = temp.ToString(); bindData(); } protected void LinkButton4_Click(object sender, EventArgs e) { this.Label2.Text = this.Label4.Text; bindData(); }
數據庫分頁讀取