Sunday, March 29, 2015

Facing problem while using SharePoint SPGridView paging

Hi All,


I am working on SharePoint 2013 Server side development. Today I was trying to bind the data in SPGridView. The things are working fine except one issue. I enabled the grouping in Grid View. This Grouping functionality is working fine for no paging but if I am enabling the Group(ing) functionality then the grouping is not working on page2.


The grouping is working on page 1 but on click of '2' (for page 2) the data shown without group. All the data is OK but it should be in group.


Please find the code snippet below:


Grouping Enabled:



protected override void OnLoad(EventArgs e)
{
oGrid.AllowGrouping = true;
oGrid.GroupField = "MainActivities";
oGrid.GroupDescriptionField = "MainActivities";
oGrid.GroupFieldDisplayName = "MainActivities";
oGrid.AllowGroupCollapse = true;

try
{
if (!IsPostBack)
{
DisplayGridBasedOnFilter();
}
}
catch (Exception ex)
{
throw ex;
}

}



//Bind data in grid view control with "oGrid.PagerTemplate = null;"

private void bindGridControl(SPQuery objSPQuery)
{

DataTable table = getSPListItemByQuery(objSPQuery);
oGrid.PagerTemplate = null;
if (table.Rows.Count > 0)
{
DataView dataSource = table.DefaultView;
dataSource.Sort = "MainActivities";
//table.DefaultView.Sort = "MainActivities";
oGrid.DataSource = dataSource;
oGrid.DataBind();

}
}





//Page indexing

protected void oGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
try
{
oGrid.PageIndex = e.NewPageIndex;
DisplayGridBasedOnFilter();
}
catch
{
throw;
}
}


Please let me know if any details are required.


Please help.


Thanks.




No comments:

Post a Comment