Aaron Hanusa
Top achievements
Rank 1
Aaron Hanusa
asked on 29 Oct 2009, 06:52 PM
Sorry to repost, I feel the subject needed a more fitting description
I am using a RadGrid and have its EditMode set to "Popup". Within EditFormSettings.FormTemplate, I have the following control declared:
<
telerik:RadDatePicker ID="txtEffectiveDate" runat="server" Width="150px" SelectedDate='<%# Bind("EffectiveDate") %>'></telerik:RadDatePicker>
The bound property, "EffectiveDate", is of nullable type DateTime?
The grid is supporting Add and Edit mode. When I edit an object whose EffectiveDate value is null, I don't have any issue. However, when I go to Add a new item, I get the following issue:
Specified cast is not valid.
Any thoughts?
Thanks much!
Aaron
6 Answers, 1 is accepted
0
Aaron Hanusa
Top achievements
Rank 1
answered on 29 Oct 2009, 11:00 PM
So no one at Telerik can figure this out? If it's a bug in the control, I'd appreciate being told so, so that I can choose an alternate solution.
Thanks
Thanks
0
Shinu
Top achievements
Rank 2
answered on 30 Oct 2009, 06:13 AM
Hi,
You need to bind the DbSelectedDate property of the date picker instance to avoid the exception so that when the control doesn't have a value it would be left blank in the insert form.
ASPX:
Thanks,
Shinu
You need to bind the DbSelectedDate property of the date picker instance to avoid the exception so that when the control doesn't have a value it would be left blank in the insert form.
ASPX:
| <telerik:RadDatePicker ID="RadDatePicker1" Runat="server" Culture="English (United States)" |
| DbSelectedDate='<%# Bind("DateReported") %>' Skin="" > |
| <dateinput skin=""></dateinput> |
| </telerik:RadDatePicker> |
Thanks,
Shinu
0
Aaron Hanusa
Top achievements
Rank 1
answered on 30 Oct 2009, 02:29 PM
Hi Shinu, thanks for the reply.
Unfortunately I receive this error now:
DataBinding: 'Telerik.Web.UI.GridInsertionObject' does not contain a property with the name 'EffectiveDate'.
In case you need it, here is my Grid declaration:
Unfortunately I receive this error now:
DataBinding: 'Telerik.Web.UI.GridInsertionObject' does not contain a property with the name 'EffectiveDate'.
In case you need it, here is my Grid declaration:
| <telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True" |
| AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowPaging="True" AutoGenerateColumns="false" |
| DataSourceID="orgProjectDataSource" OnRowDrop="RadGrid1_RowDrop" OnItemInserted="RadGrid1_ItemInserted" |
| AllowSorting="true" AllowMultiRowSelection="false"> |
| <MasterTableView EditMode="PopUp" CommandItemDisplay="Top" DataKeyNames="CoreAbilityID"> |
| <Columns> |
| <telerik:GridEditCommandColumn ButtonType="ImageButton" HeaderStyle-Width="3%" /> |
| <telerik:GridBoundColumn UniqueName="Description" HeaderText="Description" DataField="Description"></telerik:GridBoundColumn> |
| <telerik:GridBoundColumn UniqueName="EffectiveDate" HeaderText="EffectiveDate" DataField="EffectiveDateString"></telerik:GridBoundColumn> |
| <telerik:GridBoundColumn UniqueName="EndDate" HeaderText="EndDate" DataField="EndDateString"></telerik:GridBoundColumn> |
| <telerik:GridButtonColumn CommandName="Delete" Text="Delete" ButtonType="ImageButton" HeaderStyle-Width="3%"></telerik:GridButtonColumn> |
| </Columns> |
| <EditFormSettings PopUpSettings-Modal="true" FormTableStyle-Width="225" PopUpSettings-Height="265" FormTableStyle-CellPadding="1" EditFormType="Template"> |
| <FormTemplate> |
| <br /> |
| <div class="dialog"> |
| <label for="txtDescription">Description</label><br /> |
| <asp:TextBox ID="txtDescription" Text='<%# Bind("Description") %>' runat="server" Width="150px"></asp:TextBox> |
| <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="txtDescription" Text="Description Required" runat="server" EnableClientScript="true"></asp:RequiredFieldValidator> |
| </div> |
| <div class="dialog"> |
| <label for="txtEffectiveDate">Effective Date</label><br /> |
| <telerik:RadDatePicker ID="txtEffectiveDate" runat="server" Width="150px" DbSelectedDate='<%# Bind("EffectiveDate") %>'></telerik:RadDatePicker> |
| </div> |
| <div class="dialog"> |
| <label for="txtEndDate">End Date</label><br /> |
| <telerik:RadDatePicker ID="txtEndDate" runat="server" Width="150px" DbSelectedDate='<%# Bind("EndDate") %>'></telerik:RadDatePicker> |
| </div> |
| <div class="commands"> |
| <asp:LinkButton ID="saveButton" runat="server" Text="Save" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>' /> |
| <asp:LinkButton ID="cancelButton" runat="server" Text="Cancel" CommandName="Cancel"></asp:LinkButton> |
| </div> |
| </FormTemplate> |
| </EditFormSettings> |
| </MasterTableView> |
| <ClientSettings AllowRowsDragDrop="true"> |
| <Selecting AllowRowSelect="True" /> |
| </ClientSettings> |
| </telerik:RadGrid> |
0
Princy
Top achievements
Rank 2
answered on 02 Nov 2009, 09:22 AM
Hello Aaron,
Here's a help document which you can refer to, inorder to avoid this error. As mentioned in the document, you can preset the default value of the control when binding to a grid item on the InitInsertCommand.
Known reasons for error messages
Thanks
Princy.
Here's a help document which you can refer to, inorder to avoid this error. As mentioned in the document, you can preset the default value of the control when binding to a grid item on the InitInsertCommand.
Known reasons for error messages
Thanks
Princy.
0
Aaron Hanusa
Top achievements
Rank 1
answered on 02 Nov 2009, 02:23 PM
Hi Princy,
This solution seems hackish to me. Why is it that if I just use textBoxes and bind, it works just fine?
For example, using the following declaration in InsertMode works just fine:
In the above scenario, there is no need to handle the ItemCommand event and populate a temporary dictionary object with garbage values to "fake it out". But once you introduce the RadDatePicker to the FormTemplate, then all bets are off. You are left to resort to a hackish solution.
Seems like a bug to me?
This solution seems hackish to me. Why is it that if I just use textBoxes and bind, it works just fine?
For example, using the following declaration in InsertMode works just fine:
| <EditFormSettings PopUpSettings-Modal="true" FormTableStyle-Width="225" PopUpSettings-Height="265" FormTableStyle-CellPadding="1" EditFormType="Template"> |
| <FormTemplate> |
| <br /> |
| <div class="dialog"> |
| <label for="txtDescription">Description</label><br /> |
| <asp:TextBox ID="txtDescription" Text='<%# Bind("Description") %>' runat="server" Width="150px"></asp:TextBox> |
| .... |
In the above scenario, there is no need to handle the ItemCommand event and populate a temporary dictionary object with garbage values to "fake it out". But once you introduce the RadDatePicker to the FormTemplate, then all bets are off. You are left to resort to a hackish solution.
Seems like a bug to me?
0
Princy
Top achievements
Rank 2
answered on 03 Nov 2009, 09:26 AM
Hi Aaron,
The selected value of the dropdownlist cannot bind to a null field and eventually fails throwing the error.The trick is that you can add items to the dropdown list by declaration along with setting the AppenddataboundItems property to True. Setting the value to "" causes the bind to give back a "" if the field contains NULL. This is not required in the case of a textbox where it substitutes a null value from the db with an empty string.
Thanks,
Princy
The selected value of the dropdownlist cannot bind to a null field and eventually fails throwing the error.The trick is that you can add items to the dropdown list by declaration along with setting the AppenddataboundItems property to True. Setting the value to "" causes the bind to give back a "" if the field contains NULL. This is not required in the case of a textbox where it substitutes a null value from the db with an empty string.
Thanks,
Princy