datalist能分页,但不能跳转,这是问什么啊
publicintendPage;privatevoidindexListBind(){try{intcurPage=Convert.ToInt32(this.lb_pa...
public int endPage;
private void indexListBind()
{
try
{
int curPage = Convert.ToInt32(this.lb_pageIndex.Text) - 1;//获取当前页码,我用的是一个lable.当了中间变量
SqlConnection con = sqlc.GetCon();
con.Open();
SqlDataAdapter sda = new SqlDataAdapter("select * from FY", con);
DataSet ds = new DataSet();
sda.Fill(ds, "FY");
PagedDataSource ps = new PagedDataSource();//实例化分页数据源
ps.DataSource = ds.Tables[0].DefaultView;//将要绑定在datalist上的datatable给分页数据源
ps.AllowPaging = true;
ps.PageSize = 1;//每页显示几条记录
ps.CurrentPageIndex = curPage;//设置当前页的索引(当前页码减1就是)
this.btn_up.Enabled = true;
this.btn_next.Enabled = true;
this.btn_frist.Enabled = true;
this.btn_end.Enabled = true;
endPage = ps.PageCount;
if (curPage == 0)//当是第一页是.上一页和首页的按钮不可用
{
this.btn_up.Enabled = false;
this.btn_frist.Enabled = false;
}
if (curPage == ps.PageCount - 1)//当是最后一页时下一页和最后一页的按钮不可用
{
this.btn_next.Enabled = false;
this.btn_end.Enabled = false;
}
this.DataList1.DataSource = ps;
this.DataList1.DataBind();
con.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
protected void btn_frist_Click(object sender, EventArgs e)
{
this.lb_pageIndex.Text = "1";
this.indexListBind();
}
protected void btn_up_Click(object sender, EventArgs e)
{
int page = int.Parse(this.lb_pageIndex.Text) - 1;
this.lb_pageIndex.Text = page.ToString();
this.indexListBind();
}
protected void btn_next_Click(object sender, EventArgs e)
{
int page = int.Parse(this.lb_pageIndex.Text) + 1;
this.lb_pageIndex.Text = page.ToString();
this.indexListBind();
}
protected void btn_end_Click(object sender, EventArgs e)
{
this.lb_pageIndex.Text = endPage.ToString();
this.indexListBind();
} 展开
private void indexListBind()
{
try
{
int curPage = Convert.ToInt32(this.lb_pageIndex.Text) - 1;//获取当前页码,我用的是一个lable.当了中间变量
SqlConnection con = sqlc.GetCon();
con.Open();
SqlDataAdapter sda = new SqlDataAdapter("select * from FY", con);
DataSet ds = new DataSet();
sda.Fill(ds, "FY");
PagedDataSource ps = new PagedDataSource();//实例化分页数据源
ps.DataSource = ds.Tables[0].DefaultView;//将要绑定在datalist上的datatable给分页数据源
ps.AllowPaging = true;
ps.PageSize = 1;//每页显示几条记录
ps.CurrentPageIndex = curPage;//设置当前页的索引(当前页码减1就是)
this.btn_up.Enabled = true;
this.btn_next.Enabled = true;
this.btn_frist.Enabled = true;
this.btn_end.Enabled = true;
endPage = ps.PageCount;
if (curPage == 0)//当是第一页是.上一页和首页的按钮不可用
{
this.btn_up.Enabled = false;
this.btn_frist.Enabled = false;
}
if (curPage == ps.PageCount - 1)//当是最后一页时下一页和最后一页的按钮不可用
{
this.btn_next.Enabled = false;
this.btn_end.Enabled = false;
}
this.DataList1.DataSource = ps;
this.DataList1.DataBind();
con.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
protected void btn_frist_Click(object sender, EventArgs e)
{
this.lb_pageIndex.Text = "1";
this.indexListBind();
}
protected void btn_up_Click(object sender, EventArgs e)
{
int page = int.Parse(this.lb_pageIndex.Text) - 1;
this.lb_pageIndex.Text = page.ToString();
this.indexListBind();
}
protected void btn_next_Click(object sender, EventArgs e)
{
int page = int.Parse(this.lb_pageIndex.Text) + 1;
this.lb_pageIndex.Text = page.ToString();
this.indexListBind();
}
protected void btn_end_Click(object sender, EventArgs e)
{
this.lb_pageIndex.Text = endPage.ToString();
this.indexListBind();
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询