码迷,mamicode.com
首页 > 数据库 > 详细

数据库分页读取

时间:2017-10-13 15:22:19      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:fill   data   label   dex   esc   desc   lda   wpa   page   

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

 

数据库分页读取

标签:fill   data   label   dex   esc   desc   lda   wpa   page   

原文地址:http://www.cnblogs.com/huichao1314/p/7661301.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!