I am converting a string that is being read from a textbox in gridview
int numTC = Convert.ToInt32(((TextBox)r开发者_StackOverflow中文版ow.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
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
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.
精彩评论