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

RadDatePicker FormTemplate

2 Answers 63 Views
Input
This is a migrated thread and some comments may be shown as answers.
Bernhard Rosenfelder
Top achievements
Rank 1
Bernhard Rosenfelder asked on 03 Nov 2010, 10:36 PM
hi,

i get an exception when using raddatepicker within grid formtemplate for creating a new item.
the raddatepicker is bound. editing existing itemes works fine.

<telerik:RadDatePicker ID="DatePickerWJBeginnDatum" runat="server"
    DateInput-DateFormat="dd.MM.yyyy"
    SelectedDate='<%# Bind("WjBeginnDatum") %>'
    Width="400px">
</telerik:RadDatePicker>

thank you for your help
bernhard

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 04 Nov 2010, 12:02 PM
Hello Bernhard ,

You can use the DbSelectedDate property instead of SelectedDate .The DbSelectedDate property behaves exactly like the SelectedDate property. The only difference is that it will not throw an exception if the new value is null or DBNull. Setting a null value will internally revert the SelectedDate to the null value, i.e. the input value will be empty.

ASPX:
<telerik:RadDatePicker DbSelectedDate='<%# Bind("WjBeginnDatum") %>' ID="DatePickerWJBeginnDatum"
                       MinDate="1/1/1800" runat="server" DateInput-DateFormat="dd.MM.yyyy" Width="400px">
 </telerik:RadDatePicker>

Another suggessition is to set the SelectedDate from code behind.
Sample code is given below.
C#:
protected void RadGrid1_ItemDataBound1(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditFormItem && e.Item.IsInEditMode && !e.Item.OwnerTableView.IsItemInserted)
    {
        GridEditFormItem editItem = (GridEditFormItem)e.Item;
        GridDataItem item = (GridDataItem)editItem.ParentItem;
        DataRowView rowview = (DataRowView)item.DataItem;
        RadDatePicker datepick = (RadDatePicker)editItem.FindControl("DatePickerWJBeginnDatum");
        datepick.SelectedDate = Convert.ToDateTime(rowview["WjBeginnDatum"].ToString());
    }
}

ASPX:
<telerik:RadDatePicker ID="DatePickerWJBeginnDatum"
                      MinDate="1/1/1800" runat="server" DateInput-DateFormat="dd.MM.yyyy" Width="400px">
 </telerik:RadDatePicker>


Thanks,
Princy.
0
Bernhard Rosenfelder
Top achievements
Rank 1
answered on 06 Nov 2010, 04:55 PM
hi princy,

thank you for your help. with dbselecteddate it works fine. i just was a bit irritated because i did not get the property
dbselecteddate as proposal in vs2010.

thank you,
bernhard
Tags
Input
Asked by
Bernhard Rosenfelder
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Bernhard Rosenfelder
Top achievements
Rank 1
Share this question
or