2011-01-06 6 views
0

내 셰어 포인트 웹 파트에서 간단한 페이징을 구현하려고합니다. 간단한 칼럼이있는 뉴스 기사 목록이 하나 있습니다. 나는 그 페이지에서 5를 가질 수 있고 바닥에 숫자로 된 페이징을 가질 수 있기를 원한다. 나는 splistitemcollectionposition를 이해하려고 노력하는 그물을지나 갔다. 그러나 운없이. 누군가가 도와 줘요 수 있다면 당신은Sharepoint 2010 사용자 정의 웹 파트 페이징

크리스

에게

많은 감사 나에게 간단한 코드 예제 또는 일부 guidanc을 줄 수

답변

0

나는 것 같이 그들이 페이징 및 다른 많은 멋진 기능을 구현하는 것, SPDataSource과 SPGridView을 사용하는 것이 좋습니다 코드가 없거나 전혀 없습니다.

+0

이 때문에 그리드는 부적절한 프런트 엔드 웹 사이트입니다 이 사용 .. 이것은 왜 웹 파트가 올바른 해결책인지 설명합니다. – kalabo

+0

원하는 모양으로 그리드를 사용자 정의 할 수 있습니다. 마법은 페이징 백엔드를 구현하는 SPDataSource에 있으며, UI에 대한 모든 컨트롤을 사용할 수 있습니다 –

0

페이징 기능을 사용하기 위해 필요할 수있는 일부 클래스/메소드/속성에 대한 가이드를 사용하십시오. 이 코드는 컴파일되지 않는다는 것을 알아 두십시오. 페이징, 정렬, 그룹화 및 캐싱을 포함하는 자체 목록 결과 프레임 워크에있는 다양한 코드 조각을 가져 왔습니다. 그것은 당신을 시작하게하는 데 충분해야합니다.

public class PagedListResults : System.Web.UI.WebControls.WebParts.WebPart { 

    protected SPPagedGridView oGrid; 

    protected override void CreateChildControls() { 
     this.oGrid = new SPPagedGridView(); 
     oGrid.AllowPaging = true; 
     oGrid.PageIndexChanging += new GridViewPageEventHandler(oGrid_PageIndexChanging); 
     oGrid.PagerTemplate = null; // Must be called after Controls.Add(oGrid) 
     oGrid.PagerSettings.Mode = PagerButtons.NumericFirstLast; 
     oGrid.PagerSettings.PageButtonCount = 3; 
     oGrid.PagerSettings.Position = PagerPosition.TopAndBottom; 
     base.CreateChildControls(); 
    } 

    public override void DataBind() { 
     base.DataBind(); 

     SPQuery q = new SPQuery(); 
     q.RowLimit = (uint)info.PageSize; 
     if (!string.IsNullOrEmpty(info.PagingInfoData)) { 
      SPListItemCollectionPosition pos = new SPListItemCollectionPosition(info.PagingInfoData); 
      q.ListItemCollectionPosition = pos; 
     } else { 
      //1st page, dont need a position, and using a position breaks things 
     } 
     q.Query = info.Caml; 
     SPListItemCollection items = SPContext.Current.List.GetItems(q); 

     FilterInfo info = null; 
     string tmp = "<View></View>"; 
     tmp = tmp.Replace("<View><Query>", string.Empty); 
     tmp = tmp.Replace("</Query></View>", string.Empty); 
     info.Caml = tmp; 
     info.PagingInfoData = string.Empty; 
     info.CurrentPage = oGrid.CurrentPageIndex; 
     info.PageSize = oGrid.PageSize; 
     if (oGrid.PageIndex == 0 || oGrid.CurrentPageIndex == 0) { 
      //do nothing 
     } else { 
      StringBuilder value = new StringBuilder(); 
      value.Append("Paged=TRUE"); 
      value.AppendFormat("&p_ID={0}", ViewState[KEY_PagingPrefix + "ID:" + oGrid.PageIndex]); 
      info.PagingInfoData = value.ToString(); 
     } 

     int pagecount = (int)Math.Ceiling(items.Count/(double)oGrid.PageSize); 
     for (int i = 1; i < pagecount; i++) { //not always ascending index numbers 
      ResultItem item = items[(i * oGrid.PageSize) - 1]; 
      ViewState[KEY_PagingPrefix + "ID:" + i] = item.ID; 
     } 

     oGrid.VirtualCount = items.Count; 

     DateTime time3 = DateTime.Now; 
     DataTable table = new DataTable("Data"); 
     DataBindListData(table, items); 

     this.oGrid.DataSource = table; 
     this.oGrid.DataBind(); 
     this.oGrid.PageIndex = oGrid.CurrentPageIndex; //need to reset this after DataBind 
    } 

    void oGrid_PageIndexChanging(object sender, GridViewPageEventArgs e) { 
     oGrid.PageIndex = e.NewPageIndex; 
     oGrid.CurrentPageIndex = oGrid.PageIndex; 
    } 
} 

public class FilterInfo { 
    public string Caml; 
    public string PagingInfoData; 
    public int CurrentPage; 
    public int PageSize; 
} 

public class SPPagedGridView : SPGridView { 

    protected override void InitializePager(GridViewRow row, int columnSpan, PagedDataSource pagedDataSource) { 
     pagedDataSource.AllowCustomPaging = true; 
     pagedDataSource.VirtualCount = virtualcount; 
     pagedDataSource.CurrentPageIndex = currentpageindex; 
     base.InitializePager(row, columnSpan, pagedDataSource); 
    } 

    private int virtualcount = 0; 
    public int VirtualCount { 
     get { return virtualcount; } 
     set { virtualcount = value; } 
    } 

    private int currentpageindex = 0; 
    public int CurrentPageIndex { 
     get { return currentpageindex; } 
     set { currentpageindex = value; } 
    } 
} 
관련 문제