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

How to detect if RadGrid has ever databound and/or reset the status?

6 Answers 155 Views
Grid
This is a migrated thread and some comments may be shown as answers.
swegele
Top achievements
Rank 1
swegele asked on 30 Nov 2015, 01:09 AM

I have an aspx page with RadTab (5 tabs) and RadMultiPage.

Each tab has a RadGrid which only binds (declaritively with DataSourceId) if its MultiPage is loaded.  If the user never clicks on tab 4 then the RadGrid4 never databinds.

That is good because it allows me to on_demand/lazy load the child collections on the business object that is driving the screen. The user only has to wait for the data they are interested in.  If they only visit Tab1 then only MainObject.ChildCollection1 lazy loads.  Nice and clean.

Business object is like this:

MainObject

   - ChildCollection1 (lazy load) - corresponds to Grid1

   - ChildCollection2 (lazy load) - corresponds to Grid2

...etc.

PROBLEM:  If user loads page and visits Tab1 and performs some db update on Grid1...then I have to reload MainObject after save.  Currently then I call Rebind() on all 5 grids.  This is expensive and the user may not have ever visited the other tabs.  Is there a way I can:

1.  Detect which grids have databound and only call Rebind() on those?

2.  Even better would be if I could "reset" the grid somehow so it doesn't think it has databound yet?

If there is a way to do #2 then I could only call Rebind() on the RadGrid that .Visible = True.

 

Something like this:

1. User performs some update that cause MainObject to reload from DB.

2. Detect which grid is currently visible and call Rebind on it

3. Reset all other grids so they think they have not databound yet

4. If user clicks on another tab after this...the corresponding RadGrid calls SelectObject on DataSource like normal

 

All updates are happening from RadAjaxPanel which contains tabs/multi-page/and grids

 

Thank you for your help.

Sean

 

 

6 Answers, 1 is accepted

Sort by
0
swegele
Top achievements
Rank 1
answered on 01 Dec 2015, 05:28 PM

So the basic question is how does a RadGrid know that it has databound once before and can I reset that flag so it thinks it needs to databind next time it is visible (its multi-page is shown)??

 

 

0
Viktor Tachev
Telerik team
answered on 02 Dec 2015, 01:32 PM
Hello Sean,

Note that when the Visible property of a RadGrid is set to false it should not request data from the datasource. So if you have one visible grid only the data for it should be retrieved from the database. This behavior is available out of the box and you do not need to add custom logic for it.

Then, if you would like to retrieve the data for another RadGrid control you can set it as Visible=true and call its Rebind method.

Regards,
Viktor Tachev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
swegele
Top achievements
Rank 1
answered on 02 Dec 2015, 01:39 PM

I want to know 2 things:

1.  Has the grid ever databound...meaning it might have stale data after an update on the Object it is bound to

2.  Can I reset the flag you guys use to know that a data grid needs to data bind for the first time

#2 is important because it is a passive way of ensuring the data will be fresh, ONLY if they look at that grid by clicking on the RadTab.

Your RadGrid knows when to data bind for the first time...how does it know that?  Is it something I could reset.

0
Viktor Tachev
Telerik team
answered on 04 Dec 2015, 02:10 PM
Hi Sean,

If you would like to keep track if a RadGrid has requested data you can use a flag. You can set the flag in the NeedDataSource event of the grid. This way you can know when a given grid has requested data.

With that said, the idea behind using NeedDataSource is to leave the RadGrid to request data when it needs it. With this approach you do not need to handle when the RadGrid is bound, you just need to ensure that a valid data source object is set to the DataSource property. In case you need to force the RadGrid to request the data you should call its Rebind() method.



Regards,
Viktor Tachev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
swegele
Top achievements
Rank 1
answered on 05 Dec 2015, 11:16 PM

What I need is a way to tell the RadGrid that it needs a datasource...but ONLY the next time it is visible.  I could call Rebind but that would happen right away.  If I have six RadGrids in RadMultiPages with RadTabs...only ONE of them should rebind right away (the visible tab and it's grid).  

 

Can you tell me a way to let the grid know that it's data is stale so get new data next time you are visible?

I know the RadGrid has that ability because that is how it works on the first visit to the page as you highlight different tabs.

 

Thanks,

Sean

0
Viktor Tachev
Telerik team
answered on 08 Dec 2015, 10:18 AM
Hello Sean,

In order to implement the behavior you should use the following approach.
  • When a row in the first RadGrid is selected keep a relevant value for it in a Session variable
  • The rest of the RadGrid controls will be invisible
  • When the user clicks on another tab you should set the RadGrid placed inside the tab as Visible and call Rebind for it
  • In the NeedDataSource handler for the latter RadGrid you should use the information from the Session variable to retrieve the data from the data source.

For your convenience I am attaching a sample project where the behavior is implemented. Try to use similar approach and you should be able to implement the behavior you are looking for.

Regards,
Viktor Tachev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
swegele
Top achievements
Rank 1
Answers by
swegele
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or