asp.net关于DataList分页
为什么不管用,上一页,下一页的按钮是放在外面,还是放在DataList模板里面privatevoidbind()//绑定数据源{SqlConnectionconn=new...
为什么不管用,上一页,下一页的按钮是放在外面,还是放在DataList模板里面
private void bind()//绑定数据源
{
SqlConnection conn = new SqlConnection(sqlConString);
string str = "select * from chanpin order by id desc";
SqlDataAdapter da = new SqlDataAdapter(str, conn);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
DataList1.DataSource = dt;
DataList1.DataBind();
//创建数据源
PagedDataSource pds = new PagedDataSource();
pds.DataSource = dt.DefaultView;
//允许分页
pds.AllowPaging = true;
//设置每页显示记录数
pds.PageSize = int.Parse("12");
this.DataList1.DataSource = pds;
this.DataList1.DataBind();
}
int pageCount;//总页数
int currentPage = 1;//第定义当前页
//首页
protected void lblfirst_Click(object sender, EventArgs e)
{
if (this.lblcurrent.Text == "1")
{ }
else
{
currentPage = 1;
bind();
}
}
//上一页
protected void lbtnform_Click(object sender, EventArgs e)
{
if (this.lblcurrent.Text != "1")
{
currentPage = int.Parse(this.lblcurrent.Text) - 1;
this.lblcurrent.Text = currentPage.ToString();
bind();
}
}
//下一页
protected void lbtnnext_Click(object sender, EventArgs e)
{
if (this.lblall.Text == this.lblcurrent.Text)
{
}
else
{
currentPage = int.Parse(this.lblcurrent.Text) + 1;
this.lblcurrent.Text = currentPage.ToString();
bind();
}
}
//尾页
protected void lbllast_Click(object sender, EventArgs e)
{
if (this.lblall.Text != this.lblcurrent.Text)
{
this.lblcurrent.Text = this.lblall.Text;
currentPage = int.Parse(this.lblall.Text);
bind();
}
} 展开
private void bind()//绑定数据源
{
SqlConnection conn = new SqlConnection(sqlConString);
string str = "select * from chanpin order by id desc";
SqlDataAdapter da = new SqlDataAdapter(str, conn);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
DataList1.DataSource = dt;
DataList1.DataBind();
//创建数据源
PagedDataSource pds = new PagedDataSource();
pds.DataSource = dt.DefaultView;
//允许分页
pds.AllowPaging = true;
//设置每页显示记录数
pds.PageSize = int.Parse("12");
this.DataList1.DataSource = pds;
this.DataList1.DataBind();
}
int pageCount;//总页数
int currentPage = 1;//第定义当前页
//首页
protected void lblfirst_Click(object sender, EventArgs e)
{
if (this.lblcurrent.Text == "1")
{ }
else
{
currentPage = 1;
bind();
}
}
//上一页
protected void lbtnform_Click(object sender, EventArgs e)
{
if (this.lblcurrent.Text != "1")
{
currentPage = int.Parse(this.lblcurrent.Text) - 1;
this.lblcurrent.Text = currentPage.ToString();
bind();
}
}
//下一页
protected void lbtnnext_Click(object sender, EventArgs e)
{
if (this.lblall.Text == this.lblcurrent.Text)
{
}
else
{
currentPage = int.Parse(this.lblcurrent.Text) + 1;
this.lblcurrent.Text = currentPage.ToString();
bind();
}
}
//尾页
protected void lbllast_Click(object sender, EventArgs e)
{
if (this.lblall.Text != this.lblcurrent.Text)
{
this.lblcurrent.Text = this.lblall.Text;
currentPage = int.Parse(this.lblall.Text);
bind();
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询