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

How to link Datapager and gridview programmatically

5 Answers 241 Views
DataPager
This is a migrated thread and some comments may be shown as answers.
Kiran
Top achievements
Rank 1
Kiran asked on 05 Oct 2010, 11:10 PM
Hi

I am trying to come up with a composite control which includes GridView and Date pager something similar to asp.net grid. I have AllowPagination property. I am finding it difficult as to how link datapager and gridview control in the composite control.

I have seen the sample where it says Datapager Source="{Binding Items, ElementName=radGridView}" but how i can I do the same linking in code behind.

Regards
Kiran

5 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 06 Oct 2010, 07:23 AM
Hi,

 Here is an example:

 
pager.SetBinding(RadDataPager.SourceProperty, new Binding("Items") { Source = grid });

Kind regards,
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
0
Kiran
Top achievements
Rank 1
answered on 11 Oct 2010, 06:18 AM
Hi

Though this works but partially when I add this line of code I can see the datapager is working with but Grid does not show anything do I need to set anything for the grid.

DataPager.SetBinding(TngDataPager.SourceProperty, new Binding("Items") { Source = GridView });

Thanks
Kiran
0
Vlad
Telerik team
answered on 11 Oct 2010, 07:14 AM
Hello,

 Can you post how you've set ItemsSource for the grid?

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
0
Kiran
Top achievements
Rank 1
answered on 12 Oct 2010, 09:00 AM
Hi

This is how I am using ItemSource property and Allow Paging property. Things seems to work fine when I run the screen first time but if I try to set the Grid ItemSource again my composite control crashes is there anything I need to do to un-bind and re-bind.

This is how I am trying to set Item Source using code-behind and I get a crash here.

GridView8.ItemsSource =

 

TestData.GetDepartments();

 



#region Property: ItemsSource
/// <summary>
/// Items is the collection of data that is used to generate the content of this control.
/// </summary>
public Object ItemsSource
{
    get { return GetValue(ItemsSourceProperty); }
    set { SetValue(ItemsSourceProperty, value); }
}
public static readonly DependencyProperty ItemsSourceProperty =
    DependencyProperty.Register(
        "ItemsSource", typeof(Object), typeof(TngGridView),
        new FrameworkPropertyMetadata
        {
            PropertyChangedCallback = (obj, e) =>
            {
                (obj as TngGridView).UpdateItemsSource(e.NewValue);
            }
        });
private void UpdateItemsSource(Object sel)
{
    GridView.ItemsSource = sel;
}
#endregion

Allow Pagin Property is defined likr this.

#region Property: AllowPaging
private bool _allowpaging = false;
/// <summary>
/// Sets AllowPaging
/// </summary>
[DesignOnly(true)]
public bool AllowPaging
{
    get { return _allowpaging; }
    set
    {
        _allowpaging = value;
        if (_allowpaging)
        {
            DataPager.Visibility = Visibility.Visible;
            DataPager.SetBinding(TngDataPager.SourceProperty, new Binding("Items") { Source = GridView });
            GridView.SetBinding(TngGridView.ItemsSourceProperty, new Binding("PagedSource") { Source = DataPager });
              
              
        }
         }
}
#endregion

Regards
Kiran
0
Accepted
Pavel Pavlov
Telerik team
answered on 13 Oct 2010, 09:16 AM
Hello Kiran,

The proper way for things to work would be as follows :

Data goes to  Pager.Source

GridView takes ItemsSource from Pager.PagedSource.

When new data comes, you need to change the Pager.Source , not RadGridView.ItemsSource.
And what you do is :
private void UpdateItemsSource(Object sel)
{
    GridView.ItemsSource = sel;
}

Maybe you need to change the code to update the Pager.Source instead.

In case this does not do the trick , just send me yuor project and I will do the fixes necessary for you .


Sincerely yours,
Pavel Pavlov
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
DataPager
Asked by
Kiran
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Kiran
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Share this question
or