asp.net 中嵌套的dataList如何把第一个datalist分页

最好有完整代码
2024-11-26 05:49:44
推荐回答(3个)
回答1:

你说的第一个datalist是内层的吗,首先查询出有多少条记录,这个会吧;然后确定页面大小和当前页(可以保存在一个label里,让其不可见),设置linkbutton,上一页下一页,给linkbutton设置commandName属性,然后在外层datalist的ItemCommand事件里写翻页if(e.commandname=="linkbutton的commandName")就显示下一页,比如pageIndex+1

回答2:

private void getGoods()
{
string strsql = "select * from table7 order by 流水号 ";
DataTable dt = BaseClass1.ReadTable(strsql);
PagedDataSource objPds = new PagedDataSource();
objPds.DataSource = dt.DefaultView;
objPds.AllowPaging = true;
objPds.PageSize = 8;
int CurPage = Convert.ToInt32(this.LabelPage.Text);
objPds.CurrentPageIndex = CurPage - 1;
if (objPds.CurrentPageIndex < 0)
{
objPds.CurrentPageIndex = 0;
}
if (objPds.PageCount == 1)
{
LinkButtonPrev.Enabled = false;
LinkButtonNext.Enabled = false;
}
else
{
if (CurPage == 1)
{
LinkButtonPrev.Enabled = false;
LinkButtonNext.Enabled = true;
}
if (CurPage == objPds.PageCount)
{
LinkButtonPrev.Enabled = true;
LinkButtonNext.Enabled = false;
}
}
this.LabelTotalPage.Text = Convert.ToString(objPds.PageCount);
DataList1.DataSource = objPds;
DataList1.DataBind();

}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("products.aspx");
}
protected void LinkButtonFirst_Click(object sender, EventArgs e)
{
this.LabelPage.Text = "1";
getGoods();
}
protected void LinkButtonPrev_Click(object sender, EventArgs e)
{
this.LabelPage.Text = Convert.ToString(int.Parse(this.LabelPage.Text) - 1);
getGoods();
}
protected void LinkButtonNext_Click(object sender, EventArgs e)
{
this.LabelPage.Text = Convert.ToString(int.Parse(this.LabelPage.Text) + 1);
getGoods();
}
protected void LinkButtonLast_Click(object sender, EventArgs e)
{
this.LabelPage.Text = this.LabelTotalPage.Text;
getGoods();
}
protected void DataList1_SelectedIndexChanged1(object sender, EventArgs e)
{

} 赞同0| 评论

回答3:

private void getGoods()
{
string strsql = "select * from table7 order by 流水号 ";
DataTable dt = BaseClass1.ReadTable(strsql);
PagedDataSource objPds = new PagedDataSource();
objPds.DataSource = dt.DefaultView;
objPds.AllowPaging = true;
objPds.PageSize = 8;
int CurPage = Convert.ToInt32(this.LabelPage.Text);
objPds.CurrentPageIndex = CurPage - 1;
if (objPds.CurrentPageIndex < 0)
{
objPds.CurrentPageIndex = 0;
}
if (objPds.PageCount == 1)
{
LinkButtonPrev.Enabled = false;
LinkButtonNext.Enabled = false;
}
else
{
if (CurPage == 1)
{
LinkButtonPrev.Enabled = false;
LinkButtonNext.Enabled = true;
}
if (CurPage == objPds.PageCount)
{
LinkButtonPrev.Enabled = true;
LinkButtonNext.Enabled = false;
}
}
this.LabelTotalPage.Text = Convert.ToString(objPds.PageCount);
DataList1.DataSource = objPds;
DataList1.DataBind();

}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("products.aspx");
}
protected void LinkButtonFirst_Click(object sender, EventArgs e)
{
this.LabelPage.Text = "1";
getGoods();
}
protected void LinkButtonPrev_Click(object sender, EventArgs e)
{
this.LabelPage.Text = Convert.ToString(int.Parse(this.LabelPage.Text) - 1);
getGoods();
}
protected void LinkButtonNext_Click(object sender, EventArgs e)
{
this.LabelPage.Text = Convert.ToString(int.Parse(this.LabelPage.Text) + 1);
getGoods();
}
protected void LinkButtonLast_Click(object sender, EventArgs e)
{
this.LabelPage.Text = this.LabelTotalPage.Text;
getGoods();
}
protected void DataList1_SelectedIndexChanged1(object sender, EventArgs e)
{

}