我编写了一个这样的控制,需要一些代码…有很多决定要作出。
public class SimplePagerLinkGenerator : IPagerLinkGenerator
{
private PagingDisplaySettings _displaySettings;
public SimplePagerLinkGenerator(PagingDisplaySettings displaySettings)
{
this._displaySettings = displaySettings;
}
public PageLinkData[] GetPagesLinkData(uint crtPageIndex, uint pageCount, ushort pageSize,
string urlLinkTemplate)
{
int i, crtPage = (int)crtPageIndex, pageCnt = (int)pageCount,
pgInnerCnt = (int)this._displaySettings.PagesBeforeOrAfterCurrent,
pgEndCnt = (int)this._displaySettings.PagesShownAtEndingsCount;
int innerBlockStart = crtPage - pgInnerCnt;
int innerBlockEnd = crtPage + pgInnerCnt;
int innerBlockStartNormalized = innerBlockStart < 1 ? 1 : innerBlockStart;
int innerBlockEndNormalized = innerBlockEnd > pageCount ? pageCnt : innerBlockEnd;
List<PageLinkData> result = new List<PageLinkData>(2 * pgEndCnt + 3 + 2 * pgInnerCnt);
for (i = 1; i <= pgEndCnt && i <= pageCount; i++)
result.Add(new PageLinkData(i, i == crtPage, urlLinkTemplate, pageSize));
if (i > pageCount)
return result.ToArray();
if (innerBlockStart > pgEndCnt + 1)
{
result.Add(PageLinkData.Ellipsis);
for (i = innerBlockStart; i <= innerBlockEndNormalized; i++)
result.Add(new PageLinkData(i, i == crtPage, urlLinkTemplate, pageSize));
}
else
for (i = pgEndCnt + 1; i <= innerBlockEndNormalized; i++)
result.Add(new PageLinkData(i, i == crtPage, urlLinkTemplate, pageSize));
if (innerBlockEnd < pageCount - pgInnerCnt)
{
result.Add(PageLinkData.Ellipsis);
for (i = pageCnt - pgInnerCnt + 1; i <= pageCount; i++)
result.Add(new PageLinkData(i, i == crtPage, urlLinkTemplate, pageSize));
}
else
for (; i <= pageCount; i++)
result.Add(new PageLinkData(i, i == crtPage, urlLinkTemplate, pageSize));
return result.ToArray();
}
public PagingDisplaySettings DisplaySettings { get { return this._displaySettings; } }
}