2

I am converting a string that is being read from a textbox in gridview

int numTC = Convert.ToInt32(((TextBox)row.FindControl("numTC")).Text);

However it is returning the following exception:

Input string was not in a correct format.

Can anyone see anything wrong in the conversion?

Thanks

1
  • Please post complete code where you trying to access. Commented Aug 16, 2011 at 9:15

2 Answers 2

1

Make Sure that your gridview can accept only numbers you can have a filterextender using ajax and I m sure u will do that what else you can do is to check whether you have a textbox is null or not using the Function given below

if(string.IsNullOrEmpty(((TextBox)Row.FindControl("numTC")).Text)) {}

((TextBox)GridViewname.Rows[e.RowIndex].FindControl("numTC")).Text;

and

use this extender or u can use javascript as well

If it is going inside the if statement that means the value is null

 if(!string.IsNullOrEmpty(((TextBox)row.FindControl("numTC")).Text)) {} 

I have used ! sign now it will go inside the if statement if there is some value in it. and try to convert this text into integer using try catch block if u get any exception you can take whatever action you want to. Let me know if it is complete

Sign up to request clarification or add additional context in comments.

4 Comments

youre right, its not reading anything, its going in the if statement, do you have any idea how i can correct this?
If it is going inside the if statement that means the value is null
yes yes the value is null, now im trying to find out why it is null since i am inputting values. ill get back to you
what is the standard line of code to read from a textbox in gridview? im thinking i got that wrong from the start
1

It is obvious that the value of the returned in the "Text" property of the text box cannot be converted to inter, I guess you have to insure first that you are returning the correct textbox and that it contains a valid value before attempting the conversion.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.