This is a migrated thread and some comments may be shown as answers.

Grid Paging

1 Answer 25 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 15 Jul 2012, 01:42 PM
I know that this question has been asked many times but I'm having problems getting paging working with my grid. I've looked at the examples and still can't get it right. Could someone please point me in the right direction with my code?

<telerik:RadGrid ID="ProfileGrid" Width="100%" AllowFilteringByColumn="True"
            AllowSorting="True" PageSize="12" ShowFooter="True" AllowPaging="True" ViewStateMode="Enabled"
            runat="server" OnNeedDataSource="ProfileGrid_NeedDataSource" AutoGenerateColumns="false"
            GridLines="None" ShowStatusBar="true" AllowMultiRowSelection="True" DataKeyNames="ProfileID">
            <GroupingSettings CaseSensitive="false" />
            <MasterTableView>
                <Columns>
                    <telerik:GridBoundColumn HeaderText="ProfileID" DataField="ProfileID" ReadOnly="True"
                        UniqueName="ProfileID" Display="False" />
                    <telerik:GridClientSelectColumn UniqueName="CheckboxSelectColumn" />
                    <telerik:GridBoundColumn DataField="Email" HeaderText="Email" />
                    <telerik:GridBoundColumn DataField="FirstName" HeaderText="First Name" />
                    <telerik:GridBoundColumn DataField="LastName" HeaderText="Last Name" />
                    <telerik:GridBoundColumn DataField="Occupation" HeaderText="Occupation" />
                    <telerik:GridBoundColumn DataField="CompanyName" HeaderText="Company" />
                    <telerik:GridBoundColumn DataField="Source" HeaderText="Source" />
                    <telerik:GridBoundColumn DataField="ProfileLastModifiedDate" HeaderText="Modified" />
                    <telerik:GridButtonColumn Text="Delete" CommandName="Delete" />
                    <telerik:GridButtonColumn Text="View Full Profile" CommandName="View Full Profile" />
                </Columns>
            </MasterTableView>
            <ClientSettings EnableRowHoverStyle="true">
                <Selecting AllowRowSelect="True" />
            </ClientSettings>
        </telerik:RadGrid>

public partial class ProfilesGridControl : ProfileControlBase
{
 
    protected override void FillProfiles()
    {
        List<IProfile> profilesList = new List<IProfile>();
        ProfileDal profileDal = new ProfileDal();
        profilesList = profileDal.SelectAll();
        ViewState["Profiles"] = profilesList;
        ProfileGrid.DataSource = ViewState["Profiles"];
    }
 
    protected void ProfileGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        if (ViewState["Profiles"] != null)
        {
            ProfileGrid.DataSource = ViewState["Profiles"];
        }
        {
            FillProfiles();
        }
    }
 
}

The grid loads the data successfully when the page is first loaded but if I try to page I first get a grid with all of the rows I would expect but no data. Then if I page again I get no grid just a blank page. What am I doing wrong? Note profileDal.SelectAll() creates a list of IProfile business objects by querying a SQL server database using a stored procedure. Calling profileDal.SelectAll() fetches all the data required first time. The data is not being fetched page by page.

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 19 Jul 2012, 05:50 AM
Hello,

My best guess is that the data that is stored in the ViewState is different the second time RadGrid bind. You could try to verify this assumption by calling both times the FillProfiles method in the NeedDataSource event.

Additionally, you could set breakpoints in the NeedDataSource event and check how the two datasources differs.

If this does not help, prepare a sample project that replicates the issue and share it via some online sharing service.

Regards,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or