RadGrid and RadDatePicker

2 posts, 1 answers
  1. Wack
    Wack avatar
    11 posts
    Member since:
    Nov 2006

    Posted 18 Jun 2008 Link to this post

    I'm trying to use the RadDatePicker in a RadGridlike so: 

    <telerik:GridTemplateColumn HeaderText="Target Date" UniqueName="dateuomCol"> <EditItemTemplate>
    <telerik:RadDatePicker id="RadDatePicker1" Runat="server" Width="100px" />
    </EditItemTemplate>
    </telerik:GridTemplateColumn>

    I have the datepicker showing up, but I need it to display todays date when i insert a new record.  Can anyone tell me how to do this?

  2. Answer
    Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 19 Jun 2008 Link to this post

    Hello David,

    You can use the ItemCreated event handler of the Grid to find the DatePicker and set its SelectedDate like this:

    protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) 
        { 
            if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
            { 
                RadDatePicker picker = (e.Item as GridEditableItem)["dateuomCol"].Controls[1] as RadDatePicker; 
                picker.SelectedDate = System.DateTime.Today; 
            } 
        } 

    See the following help article for more details on how to reference controls in the Grid.

    Regards,
    Pavel
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top