I'm using RadControls for ASP.NET AJAX Q2 2009. I have a RadGrid set up with a GridDateTimeColumn with the PickerType="DatePicker" and EditMode="InPlace".
Thanks in advance.
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" GridLines="None" |
Width="100%" Height="175px" DataSourceID="odsDataSource" OnItemCreated="RadGrid1_ItemCreated" |
ShowStatusBar="True" OnPreRender="RadGrid1_PreRender" OnItemInserted="RadGrid1_ItemInserted" |
OnItemUpdated="RadGrid1_ItemUpdated" OnItemCommand="RadGrid1_ItemCommand" OnInsertCommand="RadGrid1_InsertCommand" |
OnUpdateCommand="RadGrid1_UpdateCommand" OnDeleteCommand="RadGrid1_DeleteCommand" |
ClientSettings-Scrolling-AllowScroll="true" ClientSettings-Scrolling-SaveScrollPosition="true" |
AllowAutomaticInserts="False" AllowAutomaticUpdates="False" AllowAutomaticDeletes="false" |
Visible="False" HeaderStyle-Font-Size="XX-Small" HeaderStyle-Font-Bold="true" |
Font-Size="XX-Small" TabIndex="50"> |
<MasterTableView CommandItemDisplay="Top" CommandItemSettings-RefreshText="Refresh List" DataSourceID="odsDataSource" |
ShowHeadersWhenNoRecords="true" NoMasterRecordsText="No Entries" EditMode="InPlace" |
ItemStyle-Font-Size="XX-Small" Font-Size="XX-Small" EditItemStyle-Font-Size="XX-Small" |
EditFormSettings-EditColumn-ItemStyle-Font-Size="XX-Small"> |
<CommandItemSettings RefreshText="Refresh List"></CommandItemSettings> |
<Columns> |
<telerik:GridEditCommandColumn ButtonType="LinkButton" EditText="Edit" CancelText="Cancel" |
UniqueName="EditColumn" ItemStyle-Font-Size="XX-Small"> |
</telerik:GridEditCommandColumn> |
<telerik:GridDateTimeColumn DataField="CHECKER_DATE" HeaderText="Date" ReadOnly="false" |
UniqueName="CHECKER_DATE" ItemStyle-Font-Size="XX-Small" ColumnEditorID="CHECKER_DATE" |
Resizable="false" PickerType="DatePicker" DataFormatString="{0:MM/dd/yyyy}" MinDate="2007-10-01"> |
</telerik:GridDateTimeColumn> |
</Columns> <!-- Big grid. Other columns truncated to save space --> |
</MasterTableView> |
</telerik:RadGrid> |
When I click on a row's "Edit' link, the DatePicker shows the correct date from the database in both the box and in the calendar. However, when I click on "Insert" I want the current date to be selected and I can't seem to get that to happen.
In the codebehind page I have this method set up:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) |
{ |
if (e.Item is GridEditableItem && e.Item.IsInEditMode) |
{ |
GridEditableItem item = e.Item as GridEditableItem; |
if (e.Item.ItemIndex == -1) |
{ |
(editedItem["CHECKER_DATE"].Controls[0] as RadDatePicker).SelectedDate = DateTime.Today; |
} |
} |
} |
I have also tried it like this:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) |
{ |
if (e.Item is GridEditableItem && e.Item.IsInEditMode) |
{ |
GridEditableItem item = e.Item as GridEditableItem; |
if ((editedItem["CHECKER_DATE"].Controls[0] as RadDatePicker).SelectedDate.ToString().Length == 0) |
{ |
editedItem["CHECKER_DATE"].Controls[0] as RadDatePicker).SelectedDate = DateTime.Today; |
} |
} |
} |
I have also tried editedItem["CHECKER_DATE"].Controls[0] as RadDatePicker).SelectedDate = DateTime.Now.Date; with no success.
I've tried some other methods which I've found on Telerik's web site and some other places and I can't seem to get this date to pre-select.
Any ideas of what I can do to make this work.
Thanks in advance.