数据库分页读取

.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>
&nbsp; &nbsp; &nbsp;
<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();
}

 

转载于:https://www.cnblogs.com/huichao1314/p/7661301.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值