在绑定数据源的时候调用下面这段代码
//根据当前页码检查分页要显示那一段的分页页码
private int CheckPage(int curPage)
{
if (curPage.ToString().Length == 1)
{
return 0;
}
else
{
string tml = curPage.ToString().Substring(0, curPage.ToString().Length - 1);
/*如果当前是第十页(或二十页)就会有这些情况,本来要到前十页的却到了十到二十页
* 当取得的页码第一位的值乘十后等于当前页码,就把取得的页码第一位减一后乘十返回
* 否则就返回取得的页码第一位的值乘十的值
*/
return Convert.ToInt32(tml) * 10 == curPage ? (Convert.ToInt32(tml)-1)*10 : Convert.ToInt32(tml) * 10;
}
}
//生成一系列页码
private void HtmlPage(int Page,int curPage)
{
StringBuilder htm=new StringBuilder();
int Num=Page+10;
if (Num <= Convert.ToInt32(LbCount.Text))
{
for (int i = 0; i < 10; i++)
{
htm.AppendFormat("{0}/", Format(Page + i + 1, curPage));
}
}
else if (Num > Convert.ToInt32(LbCount.Text))
{
int Count = Convert.ToInt32(LbCount.Text) - Page;
for (int i = 0; i < Count; i++)
{
htm.AppendFormat("{0}/", Format(Page + i + 1, curPage));
}
}
htm.Remove(htm.Length-1,1);
//添加到你想要到位置上
tab.Rows[1].Cells[2].InnerHtml = htm.ToString();
}
//格式化页码
private string Format(int i,int curPage)
{
return curPage == i ? string.Format("{0}{1}{2}", "<span class='S10ptBold70AE03'> ", i, " </span>") : string.Format("{0}{1}{2}{3}{4}",
" <a href='ScreenShots.aspx?Page=", i, "'>", i, "</a> ");
}
private int CheckPage(int curPage)
{
if (curPage.ToString().Length == 1)
{
return 0;
}
else
{
string tml = curPage.ToString().Substring(0, curPage.ToString().Length - 1);
/*如果当前是第十页(或二十页)就会有这些情况,本来要到前十页的却到了十到二十页
* 当取得的页码第一位的值乘十后等于当前页码,就把取得的页码第一位减一后乘十返回
* 否则就返回取得的页码第一位的值乘十的值
*/
return Convert.ToInt32(tml) * 10 == curPage ? (Convert.ToInt32(tml)-1)*10 : Convert.ToInt32(tml) * 10;
}
}
//生成一系列页码
private void HtmlPage(int Page,int curPage)
{
StringBuilder htm=new StringBuilder();
int Num=Page+10;
if (Num <= Convert.ToInt32(LbCount.Text))
{
for (int i = 0; i < 10; i++)
{
htm.AppendFormat("{0}/", Format(Page + i + 1, curPage));
}
}
else if (Num > Convert.ToInt32(LbCount.Text))
{
int Count = Convert.ToInt32(LbCount.Text) - Page;
for (int i = 0; i < Count; i++)
{
htm.AppendFormat("{0}/", Format(Page + i + 1, curPage));
}
}
htm.Remove(htm.Length-1,1);
//添加到你想要到位置上
tab.Rows[1].Cells[2].InnerHtml = htm.ToString();
}
//格式化页码
private string Format(int i,int curPage)
{
return curPage == i ? string.Format("{0}{1}{2}", "<span class='S10ptBold70AE03'> ", i, " </span>") : string.Format("{0}{1}{2}{3}{4}",
" <a href='ScreenShots.aspx?Page=", i, "'>", i, "</a> ");
}