新手求助。问一个分页代码的一部分(currentpageindex相关)
这里边加红一段的作用求解释!
private void getGoods()
{
//获取数据
string strsql = "select * from 新闻信息 where 新闻类别 like '" + Request.Params["id"].ToString() + "' order by 流水号 desc";
DataTable dt = BaseClass1.ReadTable(strsql);
//实现分页
PagedDataSource objPds = new PagedDataSource();
objPds.DataSource = dt.DefaultView;
objPds.AllowPaging = true;
objPds.PageSize = 12;
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);
GridView1.DataSource = objPds;
GridView1.DataBind();