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

Binding Numeric TextBox to int Field

4 Answers 414 Views
Input
This is a migrated thread and some comments may be shown as answers.
Chris T.
Top achievements
Rank 1
Chris T. asked on 11 Jun 2008, 01:41 PM
Maybe there's an easy way to do this that I'm missing, but I'm pulling my hair out here.

I have a class that has a field...for example:
protected int? _MNIIdentityID;  
public int? MNIIdentityID {  
    get { return _MNIIdentityID; }  
    set { _MNIIdentityID = value; }  

When I bind an instance of the class to a FormView, I can't seem to make it work. 

If I bind to Text, I can't get empty strings to work correctly.

If I bind to DbValue, I get an error that it can't convert double? to int?.

Any suggestions, short of using a non-numeric textbox?

4 Answers, 1 is accepted

Sort by
0
Missing User
answered on 12 Jun 2008, 07:45 AM
Hi Chris,


We are having some trouble understanding the problem. I have prepared a sample page which demonstrates the correct behavior. Can you please modify it to show us what goes wrong? I am afraid without an example we will not be able to provide much assistance.

Sincerely yours,
Plamen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Chris T.
Top achievements
Rank 1
answered on 16 Jun 2008, 04:58 PM
Sorry it took me a bit to get back to this issue.

I've modified and attached the project as requested.  The problem occurs when using an ObjectDataSource to do the binding.  A simple dal and bll are in the one file in App_Code.

Note that as is, binding to DBValue works great if you submit an empty string.  The bll object gets a null in the int? field.  The problem is trying to send in an actual number value.  That's when I get the "can't convert from double? to int?" bit.

Thanks for taking a look!

Modified Example Code
0
Accepted
Missing User
answered on 19 Jun 2008, 11:29 AM
Hello Chris,

You can use the ItemUpdating event handler. The FormView control raises the ItemUpdating event when an Update button within the control is clicked, but before the FormView control updates the record. Here is an example:

    protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e) 
    { 
        e.NewValues[0] = Convert.ToInt32(e.NewValues[0]); 
    } 

Please find attached a sample web application that demonstrates the needed approach. Take a look at it, and do not hesitate to contact me if you have other questions and/or problems.



Sincerely yours,
Plamen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Chris T.
Top achievements
Rank 1
answered on 19 Jun 2008, 12:02 PM
Plamen,

Works great!

I'm aware this wasn't a telerik error, but a lack of complete ASP.NET knowledge on my part...thanks for taking the time to help anyway!

-Chris
Tags
Input
Asked by
Chris T.
Top achievements
Rank 1
Answers by
Missing User
Chris T.
Top achievements
Rank 1
Share this question
or