//分页初始化
btnFirst.Enabled = true;
btnPrev.Enabled = true;
btnNext.Enabled = true;
btnLast.Enabled = true;
LblCurrentIndex.Visible = true;
LblPageCount.Visible = true;
LblRecordCount.Visible = true;
LblCurrentIndex.Text = "第 " + (PlatformsGridView.PageIndex + 1).ToString() + " 页";
LblPageCount.Text = "共 " + PlatformsGridView.PageCount.ToString() + " 页";
LblRecordCount.Text = "总共 " + list.Count() + " 条";
//如果Gridview的行数位0
if (PlatformsGridView.Rows.Count == 0)
{
btnFirst.Enabled = false;
btnPrev.Enabled = false;
btnNext.Enabled = false;
btnLast.Enabled = false;
LblCurrentIndex.Visible = false;
LblPageCount.Visible = false;
LblRecordCount.Visible = false;
}
//如果Gridview的页数为1
else if (PlatformsGridView.PageCount == 1)
{
btnFirst.Enabled = false;
btnPrev.Enabled = false;
btnNext.Enabled = false;
btnLast.Enabled = false;
}
//如果Gridview的页数大于1
else if (PlatformsGridView.PageCount > 1)
{
if (PlatformsGridView.PageIndex == 0)
{
btnFirst.Enabled = false;
btnPrev.Enabled = false;
btnNext.Enabled = true;
btnLast.Enabled = true;
}
else if (PlatformsGridView.PageIndex == PlatformsGridView.PageCount - 1)
{
btnFirst.Enabled = true;
btnPrev.Enabled = true;
btnNext.Enabled = false;
btnLast.Enabled = false;
}
else
{
btnFirst.Enabled = true;
btnPrev.Enabled = true;
btnNext.Enabled = true;
btnLast.Enabled = true;
}
}
// 计算生成分页页码,分别为:"首 页" "上一页" "下一页" "尾 页"
btnFirst.CommandName = "1";
btnPrev.CommandName = (PlatformsGridView.PageIndex == 0 ? "1" : PlatformsGridView.PageIndex.ToString());
btnNext.CommandName = (PlatformsGridView.PageCount == 1 ? PlatformsGridView.PageCount.ToString() : (PlatformsGridView.PageIndex + 2).ToString());
btnLast.CommandName = PlatformsGridView.PageCount.ToString();