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

RadNumericTextBox in EditForm

1 Answer 271 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
mike asked on 28 Aug 2008, 10:58 AM
I have a FormTemplate which I use for both edit and insert actions in my radGrid. I use a RadNumericTextBox within the template, and declare it as follows:


telerik:RadNumericTextBox ID="txtThreshold" runat="server" Width="104px" Value='<%# DataBinder.Eval(Container,"DataItem.threshold") %>'></telerik:RadNumericTextBox>

This works fine for editing, but when I try to use it for inserting I always get an InvalidCastException: "The specified cast is invalid" with the folowing stack trace:

   at ASP.configuration_alerts_aspx.__DataBinding__control24(Object sender, EventArgs e) in d:\Projects\WebMonitor\Web\Configuration\Alerts.aspx:line 77
   at System.Web.UI.Control.OnDataBinding(EventArgs e)
   at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
   at System.Web.UI.Control.DataBind()
   at System.Web.UI.Control.DataBindChildren()

Replacing the NumericTextBox with a standard TextBox works fine. I have also tried setting a custom value in the ItemCommand event, to really make sure there is a value being passed to the control:


void gridAlertTypes_ItemCommand(object source, GridCommandEventArgs e)
if  (e.CommandName == RadGrid.InitInsertCommandName)
e.Canceled = true;
 System.Collections.Specialized.ListDictionary newValues = new  System.Collections.Specialized.ListDictionary();newValues["description"] = "New description";
 newValues["threshold"] = 55;

But I still get the same error. I have also tried to declare the control so that the DataBinding only happens when in edit mode, and for insert I declare a hard-coded value of 0:

<telerik:RadNumericTextBox ID="txtThreshold" runat="server" Width="104px" Value='<%# (Container is GridEditFormInsertItem) ? 0 : DataBinder.Eval(Container,"DataItem.threshold") %>'></telerik:RadNumericTextBox>

But still no luck! I tried putting double quotes around the 0 as well. Which is strange, because if I use Value='0' that works fine, effectivly thats what the above statement should do when in insert mode. Any help would be appreciated!



1 Answer, 1 is accepted

Sort by
Missing User
answered on 28 Aug 2008, 11:44 AM
Hi mike,

If you bind the data to the RadNumericTextBox using its DbValue property (which accepts null values) everything should be fine. Review these resources for further details:

the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Asked by
Top achievements
Rank 1
Answers by
Missing User
Share this question