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

[Solved] EnableViewState and DataSourcePersistenceMode

5 Answers 418 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jay
Top achievements
Rank 1
Jay asked on 05 Jan 2008, 11:18 PM
Is EnableViewState required to use custom paging and data binding? If I set EnableViewState to false,  RadGrid1_NeedDataSource always sets CurrentPageIndex to 0.

I have seen some help pages that say ViewState is NOT required for paging (and custom sorting).

I have seen other articles (for ASP.NET RadControls) that say set DataSourcePersistenceMode of the grid to NoPersistence to reduce the footprint.

Basically I want to reduce the VIEWSTATE (I do not want any of the data stored in VIEWSTATE -- it is created in the RadGrid1_NeedDataSource when needed.

5 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 07 Jan 2008, 03:51 PM
Hi Jay,

I have made for you small example to illustrate you how to achieve your goal in your scenario. You can find the example attached.

Greetings,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Jay
Top achievements
Rank 1
answered on 08 Jan 2008, 11:01 PM
Thanks for the reply but I think something is wrong ...

In the sample you attached, I placed a breakpoint in RadGrid1_NeedDataSource and noticed it was called twice for each page. Additionally, it did not seem to be implementing custom paging correctly. For page 4, it was returning 40 items intead of 10. For page 9, it was returning 90 items instead of 10, etc.

In the custom paging sample "Grid\Examples\Programming\CustomPaging", it uses custom paging and only calls RadGrid1_NeedDataSource once per page. And it only fills a single page at a time ... not every page up to the current.

How do I remove the viewstate from that sample (I just want to remove the overhead of saving all the data since custom paging is being used)?

Thanks again for great support!!
0
Vlad
Telerik team
answered on 14 Jan 2008, 08:41 AM
Hi Jay,

Indeed you are right. There is a small problem with my project and you can change:

    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.PageCommandName ||
            e.CommandName == RadGrid.SortCommandName)
        {
            isSorting = true;
            RadGrid1.DataSource = null;
            RadGrid1.Rebind();
        }
    }
to

    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.PageCommandName ||
            e.CommandName == RadGrid.SortCommandName)
        {
            isSorting = (e.CommandName == RadGrid.SortCommandName);
            RadGrid1.DataSource = null;
            RadGrid1.Rebind();
        }
    }

NeedDataSource will be called twice because the grid ViewState is disabled - you can check these help articles for more info:

http://www.telerik.com/help/radcontrols/prometheus/grdRebindGridOnCommandWithDataSourcePersistenceModeNoPersistence.html
http://www.telerik.com/help/radcontrols/prometheus/grdEventSequence.html

Please read DataSourcePersistenceMode = "NoPersistence" as EnableViewState = false on both links.

Generally when traditional paging is used (paged data-source) the grid will retrieve all data source items however all ViewState operations will be only with the current page items/controls (you can check the ViewState in the attached project) and my suggestion is to use turned off ViewState with traditional paging in your case.

You can find attached modified version of the previous example.


Best wishes,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Jay
Top achievements
Rank 1
answered on 31 Jan 2008, 11:27 PM
Thanks, but when I made that change, the paging does not seem to work. When I navigate to page 7, it shows page 2, Then when I navigate to page 2, it shows page 7.

Thanks,
Jay
0
Ves
Telerik team
answered on 04 Feb 2008, 03:05 PM
Hi Jay,

Please, find attached an updated version of the first sample provided by Vlad, that does not suffer from this issue. Hope this helps.

Kind regards,
Ves
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Jay
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Jay
Top achievements
Rank 1
Ves
Telerik team
Share this question
or