0

I have a SP grid view which has loads data in a IList (data added to iList from DB). When the pager pagination arrows "< >" are clicked the pager sometimes loads the same set. When I tried to debug the "myGridView_PageIndexChanging" doesn't get hit. Any reason why? And what would be a better approach for this?

Code I have is:

1) SPDataGrid:

<SharePoint:SPGridView ID="myGridView" runat="server" AutoGenerateColumns="false" AllowSorting="false" OnRowDataBound="myGridView_RowDataBound" >

pager:

<SharePoint:SPGridViewPager ID="myGridViewPager" runat="server" GridViewId="myGridView" Visible="false">

2) On page load I have set code as:

myIList = MethdToGenerateMyIList();

myGridView.AllowPaging = true;
myGridView.PageSize = 10;
myGridView.PageIndexChanging += myGridView_PageIndexChanging;

memberGridView.DataSource = myIList;
memberGridView.DataBind();

3) The page index changing method is:

private void myGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        try
        {
            myGridView.PageIndex = e.NewPageIndex;
            myGridView.DataSource = myIList;
            myGridView.DataBind();
        }
        catch (Exception ex)
        {
        }
    }
0

method 1)

asp.net

<asp:SPGridView ID="myGridView" runat="server" AllowPaging="True" GridLines="None" 
        OnPageIndexChanging="myGridView_PageIndexChanging" PageSize="10" ShowHeader="False" ShowFooter="False" /> 

c#

onload

myIList = MethdToGenerateMyIList();
memberGridView.DataSource = myIList;
memberGridView.DataBind();

gridview event

private void myGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    try
    {
        myGridView.PageIndex = e.NewPageIndex;
        myGridView.DataSource = myIList;
        myGridView.DataBind();
    }
    catch (Exception ex)
    {
    }
}

Method 2)

instead of asp.net, as you tried todo in .cs codebehind:

asp.net

<SharePoint:SPGridView ID="myGridView" runat="server" AutoGenerateColumns="false" AllowSorting="false" OnRowDataBound="myGridView_RowDataBound" >

.cs onload:

myIList = MethdToGenerateMyIList();

myGridView.AllowPaging = true;
myGridView.PageSize = 10;
myGridView.PageIndexChanging += new EventHandler(myGridView_PageIndexChanging);

memberGridView.DataSource = myIList;
memberGridView.DataBind();

grid view event

private void myGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    try
    {
        myGridView.PageIndex = e.NewPageIndex;
        myGridView.DataSource = myIList;
        myGridView.DataBind();
    }
    catch (Exception ex)
    {
    }
}
  • Thanks for the Reply I took the Method 2. And additionally set the page template to null. Works ! – Shaamil Aug 21 '14 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.