How do I bind from a database?

6 posts, 0 answers
  1. Anthony Pieper
    Anthony Pieper avatar
    8 posts
    Member since:
    Jul 2009

    Posted 20 Jul 2009 Link to this post

    I am trying to bind the datepicker to a column from a database in my xaml code.

    Normally, I have a property in the xaml as:

    Text="{Binding Mode=TwoWay Path=MyDate}"

    This is where the column MyDate is in my backend database. How do I do this with the datepicker control ?...Any example would be helpful, also any ideas in the example of how to make it nullable would be helpful.

    Thank you.
  2. Kaloyan
    Admin
    Kaloyan avatar
    920 posts

    Posted 21 Jul 2009 Link to this post

    Hello Anthony Pieper,

    RadDatePicker is not an ItemsControl, thus is doesn't support to bind it to a custom defined dates. It is only possible to set a binding expression to the SelectedDate property of the RadDatePicker.Let us know if you need more information.

    Greetings,
    Kaloyan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft banner
  4. Anthony Pieper
    Anthony Pieper avatar
    8 posts
    Member since:
    Jul 2009

    Posted 21 Jul 2009 Link to this post

    I am assuming then that I would need to read the selected date property and manually bind to my field in my object's column via the selection changed event?

    Are there any suggestions on how to take the selected date and have it populate my table object column?

    Thank you
  5. Kaloyan
    Admin
    Kaloyan avatar
    920 posts

    Posted 21 Jul 2009 Link to this post

    Hi Anthony Pieper,

    The prefer approach is to use the MVVM pattern. Your custom object will expose a property which will be bind to the SelectedDate property of the RadDatePicker using TwoWay binding. So in the setter of this object you will have a valid SelectedDate item. Attached is a sample project demonstrating the described technic.

    Sincerely yours,
    Kaloyan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. Srinivas
    Srinivas avatar
    48 posts
    Member since:
    May 2009

    Posted 03 Sep 2009 Link to this post

    Hello Kaloyan,

    I used similar mechanism to bind the date picker but the binding validation errors are not working on DatePicker. Can you please advice me how to implement binding validations on RadDatePicker?
    == XAML ==
     <telerikInput:RadDatePicker x:Name="txtEndDate" HorizontalAlignment="Left"
    Margin="3" Width="100" Culture="en-US" Grid.Row="8" Grid.Column="1"
    SelectedDate="{Binding Mode=TwoWay, Path=EndDate, NotifyOnValidationError=true, ValidatesOnExceptions=true}"/>
    == Code Behind ==
    public DateTime EndDate
    {
       get { return _EndDate; }
       set
       {
      if (value < BeginDate)
      {
        throw new Exception("End Date must be greater than Begin Date!");
      }
       _EndDate = value;
        NotifyPropertyChanged("EndDate");
     }
    }

     


    Any help is appreciated.

    Thanks
    Srinivas


  7. Kaloyan
    Admin
    Kaloyan avatar
    920 posts

    Posted 07 Sep 2009 Link to this post

    Hi Srinivas,

    Try downloading the latest binaries and give them a try.

    All the best,
    Kaloyan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top
DevCraft banner