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个回答
网易云信
2023-12-06 广告
2023-12-06 广告
UIkit是一套轻量级、模块化且易于使用的开源UI组件库,由YOOtheme团队开发。它提供了丰富的界面元素,包括按钮、表单、表格、对话框、滑块、下拉菜单、选项卡等等,适用于各种类型的网站和应用程序。UIkit还支持响应式设计,可以根据不同...
点击进入详情页
本回答由网易云信提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询