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

How to clear grid when binding to new datasource?

3 Answers 89 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Henrik
Top achievements
Rank 1
Henrik asked on 02 Jan 2011, 02:06 PM
I have noticed that grid saves its starte when it comes to :

* Filterexpression
* Sortexpression
* In edit/insert mode
* Wich page to go to

How can we reset viewstate? Why isn't this default behavior when binding new datasource?

//h

3 Answers, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 03 Jan 2011, 03:46 PM
Hi Henrik,

Some of this questions are disused in the other thread you started:
http://www.telerik.com/community/forums/aspnet-ajax/grid/how-do-i-cancel-edit-insert-form-by-code.aspx

This is the default behavior because it allows features like custom paging to work.

Here is an example based on this demo:
1) Enable custom paging.
2) Click on second page.
3) On NeedDataSource event perform request to your DataObject and return some records.
4) Set these new records as a DataSource of your grid.
Now if on step 4 you reset the paging index (because of datasource changing) then the paging index will be zero. Which is wrong - it should be one.

It is pretty much the same situation with FilterExpression an the other settings.

Best wishes,
Vasil
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Henrik
Top achievements
Rank 1
answered on 03 Jan 2011, 03:52 PM
Hi ..
If I go to page 3 and then bind a new datasourcr(table) I will end up with the grid showing page 3 ... how to prevent this? I tried setting CurrentPageIndex to 0 and it seemt o work. Don't really understand ..

//h
0
Vasil
Telerik team
answered on 03 Jan 2011, 04:33 PM
Hello Henrik,

Yes, this is the right approach. If you want to reset the CurrentPageIndex when binding to new datasource, then set yourGrid.CurrentPageindex=0;

All the best,
Vasil
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Henrik
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Henrik
Top achievements
Rank 1
Share this question
or