RadDomainDataSource problem with DataPager

5 posts, 1 answers
  1. Chris Thierry
    Chris Thierry avatar
    138 posts
    Member since:
    Jun 2010

    Posted 19 Jan 2011 Link to this post

    Hi, I'm using the new RadDomainDataSource, I have a problem with the DataPager, the first time the datapager shows me Page zero, when I click next page, it shows me page 1 wich is the same page as page 0!, is there any problem?, I send you the code:

    In my XAML file:
    <telerik:RadGridView
                x:Name="rgvEmployeeSelect"            
                Grid.Column="0"
                Grid.Row="1" 
                Margin="10,0,10,0"
                Cursor="Hand"
                AutoGenerateColumns="False" 
                AlternateRowBackground="{StaticResource GridRowBackgroundColorBrush}"
                AlternationCount="2"                        
                CanUserFreezeColumns="False"                        
                CanUserDeleteRows="False" 
                CanUserInsertRows="False"   
                ColumnWidth="*"
                IsReadOnly="True"
                ShowGroupPanel="False"
                RowIndicatorVisibility="Collapsed"             
                HorizontalAlignment="Stretch" 
                VerticalAlignment="Stretch"         
                ScrollViewer.VerticalScrollBarVisibility="Auto"
                ItemsSource="{Binding DataView, ElementName=ddsEmployeeSelectUC}" />
      
            <telerik:RadDataPager 
                x:Name="dpgEmployeeSelect"            
                Grid.Column="0"
                Grid.Row="2"             
                PageSize="50"
                DisplayMode="FirstLastPreviousNext"             
                VerticalAlignment="Center"
                HorizontalAlignment="Stretch"
                Margin="10,0,10,0"
                Source="{Binding DataView, ElementName=ddsEmployeeSelectUC}" />

    In my cs code:

    RadDomainDataSource dds = new RadDomainDataSource();
      
    dds.PageSize = 50;
    dds.Name = "ddsEmployeeSelectUC";
    dds.QueryName = "GetEmployee2";
              
    dds.QueryParameters.Add(new QueryParameter { ParameterName = "department", Value = Entity.Department });
    dds.QueryParameters.Add(new QueryParameter { ParameterName = "employeeID", Value = Entity.Employee });
      
    dds.DomainContext = this.context;
    dds.Load();
    this.Resources.Add("ddsEmployeeSelectUC", dds);

    If I chage to DomainDataSource instead of RadDomainDataSource, is working ok. Any idea?
    Thank you.
  2. Chris Thierry
    Chris Thierry avatar
    138 posts
    Member since:
    Jun 2010

    Posted 20 Jan 2011 Link to this post

    I found the problem, this is the order in the cs code:

    RadDomainDataSource dds = new RadDomainDataSource(); 
        
    dds.QueryName = "GetEmployee2";          
    dds.QueryParameters.Add(new QueryParameter { ParameterName = "department", Value = Entity.Department }); 
    dds.QueryParameters.Add(new QueryParameter { ParameterName = "employeeID", Value = Entity.Employee }); 
      
    dds.DomainContext = this.context; 
    dds.Name = "ddsEmployeeSelectUC";  
    dds.PageSize = 50; 
      
    dds.Load(); 
    this.Resources.Add("ddsEmployeeSelectUC", dds);

    PageSize should be after DomainContext.
    Thanks
  3. DevCraft banner
  4. Answer
    Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 21 Jan 2011 Link to this post

    Hi Chris Thierry,

    It is not very correct to instantiate an an user control in code behind and use it there. When RadDomainDataSource is defined in XAML two methods on it are called by the XAML parser -- BeginInit and EndInit. When you instantiate it in code-behind this methods are not called and maybe that is why it is behaving weird.

    Anyway, for cases like yours we have provided the view that RadDomainDataSource uses internally, so you can use it in such code-behind and/or MVVM scenarios. This blog describes how to use the QueryableDomainServiceCollectionView<TEntity> in an MVVM manner to gain full control over what is going on. The blog contains a comprehensive sample solution that wraps a collection view in a view model and does all kinds of things to it.

    I have also prepared a sample project based on your source code, but I have replaced RadDomainDataSource with the collection view. My sample project does not bind stuff through view models like the blog post does just for the sake of simplicity.

    I hope this helps. Let me know if there are problems.

    Regards,
    Ross
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  5. Chris Thierry
    Chris Thierry avatar
    138 posts
    Member since:
    Jun 2010

    Posted 21 Jan 2011 Link to this post

    Thank you!
  6. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 21 Jan 2011 Link to this post

    Hi Chris Thierry,

    By the way, it was exactly what I thought. If you place BeginInit() after you create it and then EndInit just before you call Load it seems to work correctly.

    But use the QueryableDomainServiceCollectionView<T> in such scenarios since it is not an UIElement.

    Best wishes,
    Ross
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Back to Top
DevCraft banner