<
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
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.
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....
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.
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
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 >>
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.
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.