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

[Solved] Loading Row Details Data Asynchronously

1 Answer 137 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
WMansour
Top achievements
Rank 1
WMansour asked on 30 Sep 2010, 08:14 AM

Hi,
I am trying to do the following:
1- I have a GridView that is bound to a collection of objects.
2- however, these objects do not contain the data required for display in RowDetails.
3- I use a WCF service to obtain the required data when the user clicks a row.
 (Using the GridView's SelectionChanged event) and when the Async call returns with the data, I
 set the template using the code:

grdMessages.RowDetailsTemplate =  
(DataTemplate)this.LayoutRoot.Resources["TextMessageDetailsTemplate"]; 
4- To do that I defined the required template for the RowDetails in the Grid.Resources:
<DataTemplate x:Key="TextMessageDetailsTemplate">  
     <templates:TextMessageDetailsTemplate />  
</DataTemplate

5- I created a Preoperty to hold the data inside the UserControl used as a template:

public partial class TextMessageDetailsTemplate : UserControl  
    private TextMessageSummary textMessageDetails;  
  
    public TextMessageSummary TextMessageDetails  
    
        get { return textMessageDetails; }  
        set 
        
            textMessageDetails = value;  
            /*  
            Set the values of the controls inside the template using  
            the data in this property, like: 
            lblMessageTitle = value.textMessageDetails.Title 
            */
        
    
  
    public TextMessageDetailsTemplate()  
    
        InitializeComponent();  
    

6- I then used a resource to hold this property and set it for the template,
so the resource defined in step 4 becomes:

<templateData:TextMessageSummary x:Key="textMessageSummary" />   
<DataTemplate x:Key="TextMessageDetailsTemplate">   
        <templates:TextMessageDetailsTemplate 
            TextMessageDetails="{StaticResource textMessageSummary}" />   
</DataTemplate

 

 


7- What I expected to happen here is that when selection changes a request for the Details data will be sent. When the request is back, the returned data is filled in the resource named "textMessageSummary" that is used to fill the property "TextMessageDetails" of the DetailsTemplate.
Then after that when I set the RowDetailTemplate, the template control will have its "TextMessageDetails" property filled with the required data and since the setter of this property fills the data in the required fields, then the template will show with the correct data.

8- However, what happens is that the first time I click a row, the data shows correctly, but after that, every click shows the data of the previously clicked row.
So, when I click the row "Message1" the data shows up correctly in the details if this was my first click on the grid, but if I click "Message2" row now, I'll get the details of "Message1" and if I click "Message3" row after that I'll get the "Message2" details in it.

9- What I think is happening is that the template is getting its property filled before the call to the WCF service is completed. So when the event "SelectionChanged" is fired, it is too late to set the data that will be displayed in the template.

10- I know this is a bit confusing.. but is there a way to do this?

 

 

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 30 Sep 2010, 11:52 AM
Hello,

 Why not use the approach demonstrated in this blog post? When you access the child property you can perform request to the server and update desired data when response is received. In case you can use any control to display your hierarchical data since the lazy loading will be completely in your model. 

Best wishes,
Vlad
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
WMansour
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or