Bind DataPager and RadNumericUpDown in codebehind

5 posts, 1 answers
  1. Martijn
    Martijn avatar
    3 posts
    Member since:
    Jun 2010

    Posted 16 Jul 2010 Link to this post

    I have a RadGridView, a RadDataPager and a RadNumericUpDown all defined in code.

    Now i want to bind the RadDataPager.PageSize to the RadNumericUpDown.Value so the pagesize of the pager is changeable via the RadNumericUpDown control.

    Thus i try:

    RadDataPager dataPager = new ...;
    RadNumericUpDown pageSizeSelector = new ...;

    Binding b = new Binding();
    b
    .Mode = BindingMode.TwoWay;
    b
    .Source = pageSizeSelector.Value;

    pageSizeSelector
    .SetBinding(dataPager.PageSize, b);

    But this generates an error about the dataPager.PageSize not being a DependencyProperty.

    I tried the other way around:

    Binding b = new Binding();
    b
    .Mode = BindingMode.TwoWay;
    b
    .Source = dataPager.PageSize;

    dataPager.SetBinding(pageSizeSelector.Value, b);
    But that also generates an error about  pageSizeSelector.Value not being a DependencyProperty.

     What i'm a missing? Or why aren't those DPs?

    Thanks in advance!

  2. Answer
    Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 16 Jul 2010 Link to this post

    Hello Martijn,

     You need to set the binding on an object in the following way:
    dataPager.SetBinding(RadDataPager.PageSizeProperty, b);

    Basically, the first argument of SetBinding is the DependencyProperty static field in the control's class. In this case it's the static PageSizeProperty field on the RadDataPager class, which corresponds to the PageSize property of the dataPager object.

    Regards,
    Yavor Georgiev
    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
  3. DevCraft banner
  4. Martijn
    Martijn avatar
    3 posts
    Member since:
    Jun 2010

    Posted 17 Jul 2010 Link to this post

    Thanks! I now see that i got my understanding of setbinding wrong. It needs the static defintion of a DP, not an instance reference.
  5. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 19 Jul 2010 Link to this post

    Hello Martijn,

    You see an example of a RadDataPager.PageSize bound to a NumericUpDown in this online example.

    Greetings,
    Ross
    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
  6. Martijn
    Martijn avatar
    3 posts
    Member since:
    Jun 2010

    Posted 19 Jul 2010 Link to this post

    Thanks, i was aware of that example. But i wanted it to be done in codebehind, not in XAML. 

    I managed to get it done eventually (once i understood binding in code better).
Back to Top
DevCraft banner