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

How do I bind from a database?

5 Answers 113 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Anthony Pieper
Top achievements
Rank 1
Anthony Pieper asked on 21 Jul 2009, 01:16 AM
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.

5 Answers, 1 is accepted

Sort by
0
Kaloyan
Telerik team
answered on 21 Jul 2009, 08:36 AM
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.
0
Anthony Pieper
Top achievements
Rank 1
answered on 21 Jul 2009, 11:29 AM
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
0
Kaloyan
Telerik team
answered on 21 Jul 2009, 12:35 PM
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.
0
Srinivas
Top achievements
Rank 1
answered on 04 Sep 2009, 01:46 AM
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


0
Kaloyan
Telerik team
answered on 07 Sep 2009, 12:20 PM
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.
Tags
DatePicker
Asked by
Anthony Pieper
Top achievements
Rank 1
Answers by
Kaloyan
Telerik team
Anthony Pieper
Top achievements
Rank 1
Srinivas
Top achievements
Rank 1
Share this question
or