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

RadDatePicker setting default value in DateInput

7 Answers 2579 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Greg
Top achievements
Rank 1
Greg asked on 16 Mar 2011, 06:40 PM
<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>
                    </telerik:RadDatePicker>

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.

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Mar 2011, 08:36 AM
Hello Greg,

You can set the SelectedDate from codebehind after accessing the control like below.
C#:
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;
       }
   }

Thanks,
Shinu.
0
Greg
Top achievements
Rank 1
answered on 15 Apr 2011, 08:39 PM
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....
0
Maria Ilieva
Telerik team
answered on 21 Apr 2011, 08:57 AM
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.

0
Milind
Top achievements
Rank 1
answered on 23 Aug 2011, 05:25 AM
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

Milind
0
Maria Ilieva
Telerik team
answered on 25 Aug 2011, 04:22 PM
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 >>

0
Nkululeko
Top achievements
Rank 1
answered on 27 Nov 2014, 08:49 AM
Hi,

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.
0
Maria Ilieva
Telerik team
answered on 01 Dec 2014, 10:16 AM
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"

                  DataField="Date">

                  <ItemTemplate>

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

                      </telerik:RadDatePicker>

                  </ItemTemplate>

                  <EditItemTemplate>

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

                      </telerik:RadDatePicker>

                  </EditItemTemplate>

              </telerik:GridTemplateColumn>



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

Regards,
Maria Ilieva
Telerik
 

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.

 
Tags
General Discussions
Asked by
Greg
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Greg
Top achievements
Rank 1
Maria Ilieva
Telerik team
Milind
Top achievements
Rank 1
Nkululeko
Top achievements
Rank 1
Share this question
or