RadDatePicker setting default value in DateInput

8 posts, 0 answers
  1. Greg
    Greg avatar
    18 posts
    Member since:
    Oct 2010

    Posted 16 Mar 2011 Link to this post

    <telerik:RadDatePicker ID="StartDateTextBox" MinDate='<%# DateTime.Now() %>'  OnInit="StartDatePicker_Init" DbSelectedDate='<%# Bind("StartDate") %>' runat="server" Width="120"  PopupDirection="BottomRight" EnableMonthYearFastNavigation="false" TitleFormat="MMMM yyyy"    >
                           <Calendar ID="Calendar1" runat="server" CssClass="calendarBook" ShowRowHeaders="false" ></Calendar>
                           <DateInput ID="DateInput1" runat="server" Enabled="false" DateFormat="dd-MMM-yyyy"  ></DateInput>

    I have this date picker on my radgrid insert form.
    I want to set the current dbselected/selected date to today, and also show the current date in the DateInput text.
    So... basically default the "StartDate" above to the current date.

    I can't seem to find the right code to get todays date to appear in the DateInput box.
    I have it enabled="false" as I want users to only use the datepicker for dates, except for the initial default date of today.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 17 Mar 2011 Link to this post

    Hello Greg,

    You can set the SelectedDate from codebehind after accessing the control like below.
    protected void grdEmail_ItemCreated(object sender, GridItemEventArgs e)
           if (e.Item is GridEditFormInsertItem && grdEmail.MasterTableView.IsItemInserted)
               GridEditFormInsertItem editform = (GridEditFormInsertItem)e.Item;
               RadDatePicker datepcker = (RadDatePicker)editform.FindControl("StartDateTextBox");
               datepcker.SelectedDate = DateTime.Now;

  3. Greg
    Greg avatar
    18 posts
    Member since:
    Oct 2010

    Posted 15 Apr 2011 Link to this post

    Shinu, this just isn't working for me.

    In the ItemCreated event of the radgrid, I set the SelectedDate as you've shown.
    It does NOT change the value in the DateInput. It is still a blank textbox.
    I also tried setting the DateInput.Text directly and I get Text property cannot be set. String was not recognized as a valid DateTime.

    StartDatePicker.SelectedDate = myDate
    StartDatePicker.DateInput.Text = myDate

    I cannot understand how setting the selecteddate does not set the dateinput text value....
  4. Maria Ilieva
    Maria Ilieva avatar
    4017 posts

    Posted 21 Apr 2011 Link to this post

    Hi Greg,

    Please try to use the suggested code in the RadGrid_ItemDataBound event and let me know if this makes any difference.

    Kind regards,
    Maria Ilieva
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  5. Milind
    Milind avatar
    16 posts
    Member since:
    Mar 2009

    Posted 23 Aug 2011 Link to this post

    Hello Greg / Maria,

    Have you got the solution for this problem. I have the same problem. I am using inplace edit mode for radgrid. When the grid is in edit mode it correctly picks up the existing value but when it is in insert mode the raddatepicker simpy is blank. What I want to know is how can i assign a specific date to display as default date during runtime. I tried to set it thru itemcreated event. It neither shows the date nor throws any error.

    dtActiveFrom.SelectedDate = DateTime.Now;

    The statement above is simply executed. I tried debugging tracing the value assigned. To my surprise, till this statement is executed I get the object dtActiveFrom existance, on execution of the statement dtActiveFrom object is shown null.

    I will be happy if you can share any resolution you have got on this issue.

    Thanks a lot

  6. Maria Ilieva
    Maria Ilieva avatar
    4017 posts

    Posted 25 Aug 2011 Link to this post

    Hi Milind,

    Have you tried using the Shinu's approach in the RadGrid_ItemDataBound event . Give it a try and verify if it works for you.

    All the best,
    Maria Ilieva
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  7. Nkululeko
    Nkululeko avatar
    1 posts
    Member since:
    Sep 2014

    Posted 27 Nov 2014 in reply to Shinu Link to this post


    on my rad-grid uploaded date column i want to be always show today's date the user can not insert it. as well as username should always. please attached.
  8. Maria Ilieva
    Maria Ilieva avatar
    4017 posts

    Posted 01 Dec 2014 Link to this post

    Hello Nkululeko,

    In order to present today's date you can add RadDatePicker in GridTemplateColumn like this:

    <telerik:GridTemplateColumn AutoPostBackOnFilter="true" ReadOnly="true" UniqueName="Date"



                          <telerik:RadDatePicker runat="server" ID="RadDatePicker" SelectedDate='<%# System.DateTime.Today %>'>




                          <telerik:RadDatePicker runat="server" ID="RadDatePicker" SelectedDate='<%# System.DateTime.Today %>'>




    As for the Session User, I suggest that you handle the ItemCommand event of RadGrid and check there if the command is InitInsert command. Then you can insert the desired value as shown in this topic, under the
    "Setting predefined values for different column editors" section

    Maria Ilieva

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top