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

Intercepting a bind??

1 Answer 46 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 20 Aug 2011, 01:39 AM
I have a RadCalendar control that I want to show up in an ItemTemplate of a grid.

The problem is the object I am binding to (web service) returns the date in a string format, so when the bind executes, I get an invalid cast error.

Is there a way to convert the string to a datetime so that the Bind operation can be used within the selectedDate property?

Here is what I want to be able to write
<telerik:GridTemplateColumn DataField="PositionStartDate.Value" HeaderText="Position Start Date" DataType="System.DateTime">
    <ItemTemplate>
        <telerik:RadCalendar ID="uxPositionStart" runat="server" 
            SelectedDate='<%# Bind("PositionStartDate") %>'>
        </telerik:RadCalendar>
    </ItemTemplate>
</telerik:GridTemplateColumn>


But, I get the invalid cast.   This there another way to do this?

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 20 Aug 2011, 10:31 AM
Hello,

Method 1 :
<telerik:GridTemplateColumn DataField="PositionStartDate.Value" HeaderText="Position Start Date" DataType="System.DateTime">
    <ItemTemplate>
        <telerik:RadCalendar ID="uxPositionStart" runat="server"
            SelectedDate = '<%# Convert.ToDateTime(Convert.ToString(Eval("PositionStartDate"))) %>'>
        </telerik:RadCalendar>
    </ItemTemplate>
</telerik:GridTemplateColumn>

Method 2

<telerik:GridTemplateColumn DataField="PositionStartDate.Value" HeaderText="Position Start Date" DataType="System.DateTime">
    <ItemTemplate>
        <telerik:RadCalendar ID="uxPositionStart" runat="server"
            SelectedDate=''>
<asp:Lable ID="Label1" runat="server" Visible="false" Text='<%# Bind("PositionStartDate") %>' />
        </telerik:RadCalendar>
    </ItemTemplate>
</telerik:GridTemplateColumn>
itemDataBound()
{
   if(e.Item is GridDataItem)
   {
      GridDataItem item = (GridDataItem)e.Item;
      RadCalendar uxPositionStart = item.FindControl("uxPositionStart") as RadCalendar ;
      Label Label1 = item.FindControl("Label1") as Label ;
     if(!String.IsnullorEmpty(Label1.Text))
      {
      uxPositionStart.SelectedDate = Convert.ToDateTime(Label1.Text);
   
//      if you want to convert datetime with culturewise then use DateTime.TryParseExact/DateTime.TryParse
 
      }   
   }
}


Let me know If Any Concern.


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Steven
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or