1
Repeater에서 Pagination Support를 사용하려고 할 때 PagedDataSource가 나를 구출했습니다. 나는 다음과 같은 방법을 만들었으며 함정이 있는지 또는 개선의 기회가 있는지 여부를 여러분 모두와 나누고 싶습니다.Repeater에 대한 페이지 매김 지원
다음그것이,
/// <summary>
/// Create pagination for Repeater
/// </summary>
/// <param name="context">HttpContext</param>
/// <param name="obj">System.Collections.IEnumerable</param>
/// <param name="rptr">Repeater Control</param>
/// <param name="pgSize">How many records in each page</param>
/// <returns>Pagination String</returns>
public static String pagination(HttpContext context,Object obj,Repeater rptr ,int pgSize)
{
String rtn = String.Empty;
int curpage = 0;
PagedDataSource pds = new PagedDataSource();
pds.DataSource=(System.Collections.IEnumerable)obj;
pds.AllowPaging = true;
pds.PageSize = pgSize;
if (context.Request.QueryString["page"] != null)
{
curpage = Convert.ToInt32(context.Request.QueryString["page"]);
}
else
{
curpage = 1;
}
pds.CurrentPageIndex = curpage - 1;
if (!pds.IsFirstPage)
{
rtn = "<a href='?page=" + (curpage - 1).ToString() + "'>Prev</a> ";
}
if (curpage == 1 && pds.DataSourceCount > pds.PageSize)
rtn = "1";
else if (pds.DataSourceCount == 0)
rtn = "No data to display";
else if (curpage > 1 && pds.DataSourceCount > pds.PageSize)
rtn = rtn + "<a href='?page=1'>1</a> ";
for (int i = 2; i <= pds.PageCount; i++)
{
if (i == curpage)
rtn = rtn + " " + i.ToString();
else
rtn = rtn + " <a href='?page=" + i.ToString() + "'>" + i.ToString() + "</a>";
}
if (!pds.IsLastPage)
{
rtn += " <a href='?page=" + (curpage + 1).ToString() + ">Next</a>";
}
rptr.DataSource = pds;
rptr.DataBind();
return rtn;
}
정말 고마워요. 코드 가드 란 무엇입니까? – Hoque
코드 가드의 예로는 null 체크와 같은 것이 있습니다. 이 프로퍼티에 값을 할당하기 전에 객체가 null이 아닌지 확인합니다. 투표하는 것을 잊지 마십시오. – CarneyCode