views:

103

answers:

2

I have a RadGrid, with the EditFormSettings set to Template. Within my <FormTemplate> I have a RadDatePicker that I need to databind.

My code:

<telerik:RadDatePicker ID="rdpStartDate" runat="server" 
     SelectedDate='<%# Bind("StartDate") %>'>
</telerik:RadDatePicker>

"StartDate" references the column name in my DB. I have attempted to databind the control like this and get an error because the Bind() actually returns a string that cannot be stored in the SelectedDate field because it is of type DateTime.

How can I bind this AND convert this to a DateTime to be displayed in the SelectedDate property of my RadDatePicker on the Edit/Insert forms of my RadGrid?

A: 

I'm not very familiar with Bind, but the following returns a DateTime object from a string:

<%# DateTime.Parse(Eval("SelectedVal").ToString()) %>

I've tested in a Textbox

<asp:TextBox Text='<%# DateTime.Parse(Eval("SelectedVal").ToString()) %>' runat="server" />
BrunoLM
I added in this code:SelectedDate='<%# DateTime.Parse(Eval("StartDate")) %>'That returns this error:CS1502: The best overloaded method match for 'System.DateTime.Parse(string)' has some invalid arguments
j00b
A: 

SOLVED:

SelectedDate is the incorrect property to databind to, you must use the DbSelectedDate property.

DbSelectedDate='<%# Bind("Date") %>'

j00b