数据库分页读取
Posted 慧&超
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数据库分页读取相关的知识,希望对你有一定的参考价值。
.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(); }
以上是关于数据库分页读取的主要内容,如果未能解决你的问题,请参考以下文章
solr分布式索引实战分片配置读取:工具类configUtil.java,读取配置代码片段,配置实例