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

bug? custom paging and EnableViewState=false

4 Answers 217 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brian Maxwell
Top achievements
Rank 1
Brian Maxwell asked on 01 Mar 2013, 08:10 PM
I created a project using RagGrid with advanced databinding and custom paging (like the top example here: http://demos.telerik.com/aspnet-ajax/grid/examples/programming/custompaging/defaultcs.aspx) except I have viewstate for the grid disabled. My issue is when I change my page size the grid doesn't really update like it should (I'm using the default page sizes).

By default it's on 10, if I select 20 my grid rebinds but page size is still 10 in the NeedDataSource event. From there if I select page size 50, my grid rebinds but page size is 20 in NeedDataSource. The wierd part is if I select page size 10 from either of those I always get the correct page size / number of records.

I traced the events and in my scenario it looks like PageSizeChanged is being fired but the grid isn't rebinding afterwards, although it clearly rebinds correctly after PageIndexChanged.

Any help would be greatly appreciated. Thanks.

4 Answers, 1 is accepted

Sort by
0
Brian Maxwell
Top achievements
Rank 1
answered on 05 Mar 2013, 03:03 PM
bump

...is anybody else able to atleast replicate what I'm seeing?
0
Andrey
Telerik team
answered on 06 Mar 2013, 03:02 PM
Hi,

Yes, the behavior you are describing is a special case caused by the EnableViewState property. When you disable the ViewState of RadGrid, RadGrid is rebound on each postback. In this case when you change the PageSize to a bigger number, the Grid is rebound on Load event of the page yet, and then the command of changing the PageSize is fired. So, you change the page size but the Grid has already fetched the items and in the code the PageSize is changed but the Grid would not fire its NeedDataSource event because it has been already bound to data. This behavior is a design limitation in RadGrid.

The work-around for this behavior is to hook the ItemCommand event of RadGrid and set the DataSource property of RadGrid to null. Thus when the PageSize command is fired it will identity that the Grid has no datasource and will bind the proper amount of data:

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (!RadGrid1.EnableViewState && RadGrid1.AllowCustomPaging)
    {
        RadGrid1.DataSource = null;
    }
}

Greetings,
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.
0
Brian Maxwell
Top achievements
Rank 1
answered on 06 Mar 2013, 03:17 PM
Great, I can confirm that this does indeed work for me. The only problem I can see now is that when the page size changes I need to bind my data twice, is there anything I can do to prevent that?

Since the data needs to be rebound on every postback and it looks like all the relevant events for detecting page size changing are fired after that, I'll go out on a limb and guess that I'm pretty much stuck with that behavior (or revert to having viewstate enabled).
0
Andrey
Telerik team
answered on 11 Mar 2013, 10:57 AM
Hello,

Yes, disabling the ViewState does not have such impact as with ASP GridView and in some rare cases it could even decrease the performance.

I am afraid that there is no way to bind the Grid just only once. When the ViewState is disable the NeedDataSource event is fired too early and you could not control that behavior. In order to work-around the erroneous behavior you need to cancel the current datasource which will fire the NeedDataSource event for second time.

Kind 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
Brian Maxwell
Top achievements
Rank 1
Answers by
Brian Maxwell
Top achievements
Rank 1
Andrey
Telerik team
Share this question
or