Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11508

Using SPGridView with SPGridViewPager and ListItemCollectionPosition

$
0
0

Hi,

Is it possible to use SPGridView, SPGridViewPager and ListItemCollectionPosition together.

I have the Current code markup as below, but the Paging is not working.

<SharePoint:SPGridView runat="server" ID="Gridview1" AutoGenerateColumns="false" AllowPaging="true" PageSize="10"><Columns><asp:TemplateField HeaderText="Titles"><ItemTemplate><asp:Label ID="lblTitle" Text='<%# Eval("Title") %>' runat="server"></asp:Label></ItemTemplate></asp:TemplateField></Columns><PagerSettings Mode="NextPreviousFirstLast" Visible="true" NextPageText="Next |" PreviousPageText="Previous |" FirstPageText="First |" LastPageText="Last" /></SharePoint:SPGridView><SharePoint:SPGridViewPager ID="Grid1Pager" runat="server" GridViewId="Gridview1"></SharePoint:SPGridViewPager>


  using (SPSite oSite = new SPSite(Sitename))
 {
 using (SPWeb oWeb = oSite.OpenWeb())
{
 SPList lstPages = oWeb.Lists["Pages"];
 SPQuery sQuery = new SPQuery();
 sQuery.RowLimit = 10; // 10 items per page should be displayed

sQuery.Query = "<Where><Eq><FieldRef Name='_ModerationStatus'/><Value Type='ModStat'>0</Value></Eq></Where>";

sQuery.ViewFields = string.Concat("<FieldRef Name='Title' />","<FieldRef Name='EncodedAbsUrl' />");

sQuery.ViewFieldsOnly = true;

DataTable dt = new DataTable();
                                       SPListItemCollection myColl = lstPages.GetItems(sQuery);

 if (myColl.Count > 0)
 {
dt = myColl.GetDataTable();
do
{   

Gridview1.DataSource = dt;    
Gridview1.DataBind();

sQuery.ListItemCollectionPosition = myColl.ListItemCollectionPosition;
  } while (sQuery.ListItemCollectionPosition != null);
}

How to use the SPGridView, SPGridViewPager and ListItemCollectionPosition together?

I have checked various URL's, but could not find something which works with all the three.

How to use Paging with the above?

Thanks


Viewing all articles
Browse latest Browse all 11508

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>