Aaron Hanusa
Top achievements
Rank 1
Aaron Hanusa
asked on 29 Oct 2009, 03:40 PM
I am using a RadGrid and have its EditMode set to "Popup". Within EditFormSettings.FormTemplate, I have the following control declared:
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
<
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
9 Answers, 1 is accepted
0
Hi Aaron,
You need to bind the DbSelectedDate property of the date picker instance to avoid the exception (since it is of nullable type and can intercept null value on init insert operation). See this demo for more details:
http://demos.telerik.com/aspnet-ajax/calendar/examples/datepicker/databinding/defaultcs.aspx
All the best,
Pavlina
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
You need to bind the DbSelectedDate property of the date picker instance to avoid the exception (since it is of nullable type and can intercept null value on init insert operation). See this demo for more details:
http://demos.telerik.com/aspnet-ajax/calendar/examples/datepicker/databinding/defaultcs.aspx
All the best,
Pavlina
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Aaron Hanusa
Top achievements
Rank 1
answered on 02 Nov 2009, 03:20 PM
Hi Pavlina,
Thanks for the reply, but that demo does not support InsertMode. It only supports edit mode. I think that you'll find that if you take that demo, enable inserting via AllowAutomaticInserts="True", and click add, you will receive the exception that I speak of.
Thanks for the reply, but that demo does not support InsertMode. It only supports edit mode. I think that you'll find that if you take that demo, enable inserting via AllowAutomaticInserts="True", and click add, you will receive the exception that I speak of.
0
Hi Aaron,
If your problem(s) persists, it will be best if you can send us a simple running project (incl. CSS, images, skins, DB backup if needed and so on) demonstrating the problem (and step-by-step instructions on doing so). In that way we can reproduce and pinpoint the problems you're facing on our side, understand the logic of your application and provide a solution.
Regards,
Pavlina
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
If your problem(s) persists, it will be best if you can send us a simple running project (incl. CSS, images, skins, DB backup if needed and so on) demonstrating the problem (and step-by-step instructions on doing so). In that way we can reproduce and pinpoint the problems you're facing on our side, understand the logic of your application and provide a solution.
Regards,
Pavlina
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Aaron Hanusa
Top achievements
Rank 1
answered on 02 Nov 2009, 06:54 PM
There's no need for me to post my code. Take the code from your example, in which you referred me to. Add the following declaration to the RadGrid:
Run the app, click the "Add Record" button, and watch it fail.
AllowAutomaticInserts="True" |
Run the app, click the "Add Record" button, and watch it fail.
0
Hi Aaron,
I followed your scenario in order to replicate the issue but to no avail. Please find attached a simple runnable project which is working as expected. Give it a try and let me know if you need further assistance.
Regards,
Pavlina
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
I followed your scenario in order to replicate the issue but to no avail. Please find attached a simple runnable project which is working as expected. Give it a try and let me know if you need further assistance.
Regards,
Pavlina
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Aaron Hanusa
Top achievements
Rank 1
answered on 04 Nov 2009, 03:43 PM
Hi Pavlina,
Thanks very much for your continued correspondence. I see that the sample does work on InsertMode. I think I have located the culprit in my own code, but I'm still not sure why the InsertMode fails. I have been using a custom FormTempate, as seen below:
I believe the issue is within the commanding model, as defined within the saveButton (CommandName=...). Based on others feedback, to resolve this issue, I can handle the RadGrid ItemCommand event, create a "dummy" dictionary, and feed it to the popup like so:
Of course, this is less than ideal, because now I have to intervene manually, bypassing the effectiveness of data binding.
So I have decided for now to not use a custom form template to display my own look and feel. If you can see any glaring issue that I might be doing wrong as to why my particular solution doesn't work, please let me know.
Thanks again.
Thanks very much for your continued correspondence. I see that the sample does work on InsertMode. I think I have located the culprit in my own code, but I'm still not sure why the InsertMode fails. I have been using a custom FormTempate, as seen below:
<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> |
I believe the issue is within the commanding model, as defined within the saveButton (CommandName=...). Based on others feedback, to resolve this issue, I can handle the RadGrid ItemCommand event, create a "dummy" dictionary, and feed it to the popup like so:
protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
{ if (e.CommandName == RadGrid.InitInsertCommandName) |
{ |
//Add new" button clicked |
e.Canceled = true; |
//Prepare an IDictionary with the predefined values |
System.Collections.Specialized.ListDictionary newValues = new System.Collections.Specialized.ListDictionary(); |
newValues["Description"] = null; |
newValues["EffectiveDate"] = null; |
newValues["EndDate"] = null; |
//Insert the item and rebind |
e.Item.OwnerTableView.InsertItem(newValues); |
} |
Of course, this is less than ideal, because now I have to intervene manually, bypassing the effectiveness of data binding.
So I have decided for now to not use a custom form template to display my own look and feel. If you can see any glaring issue that I might be doing wrong as to why my particular solution doesn't work, please let me know.
Thanks again.
0
Hi Aaron,
If your problem(s) persists, it will be best if you can send us a simple running project (incl. CSS, images, skins, DB backup if needed and so on) demonstrating the problem (and step-by-step instructions on doing so). In that way we can reproduce and pinpoint the problems you're facing on our side, understand the logic of your application and provide a solution.
Looking forward for your reply.
Kind regards,
Pavlina
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
If your problem(s) persists, it will be best if you can send us a simple running project (incl. CSS, images, skins, DB backup if needed and so on) demonstrating the problem (and step-by-step instructions on doing so). In that way we can reproduce and pinpoint the problems you're facing on our side, understand the logic of your application and provide a solution.
Looking forward for your reply.
Kind regards,
Pavlina
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
kunal
Top achievements
Rank 1
answered on 02 Aug 2010, 06:37 AM
I have also same problem,
if any one got solution , please tell me.........................
if any one got solution , please tell me.........................
0
Hi Kunal,
To properly track the issue, I will ask you to open a formal support ticket, and send us a small working project, demonstrating your setup, and showing the unwanted behavior. We will debug it locally, and get back to you with our findings.
All the best,
Pavlina
the Telerik team
To properly track the issue, I will ask you to open a formal support ticket, and send us a small working project, demonstrating your setup, and showing the unwanted behavior. We will debug it locally, and get back to you with our findings.
All the best,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items