Click here to Skip to main content
15,909,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Can anyone please tell me what is the error in the following statement?

int a = Convert.ToInt32(GridView1.Rows[i].Cells[0].Text);


it throws an exception: "Input string was not in a correct format".
Posted
Updated 17-Jun-11 1:49am
v4
Comments
Keith Barrow 17-Jun-11 7:00am    
Yes - the exception message can tell you. My guess is that the Text property is either empty or not a number of one of the cells. You need to include the error message to get better help!
Slacker007 17-Jun-11 7:50am    
Added the obligatory code block.

"Input string was not in a correct format".
This simple means that the value of GridView1.Rows[i].Cells[0].Text is not an integer and hence when you are trying to convert it, it throws an exception.

All you need is to put a DEBUG point and see it by yourself using Visual Studio debugger.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 17-Jun-11 16:27pm    
Correct, my 5. What to do with it is a different problem.
--SA
Sandeep Mewara 18-Jun-11 2:46am    
Thanks SA.

Exactly the reason why I replied, wamted to tell root cause which none of the answer covered.
Sergey Alexandrovich Kryukov 18-Jun-11 2:52am    
Yes, this is the only answer I would accept on this page (at the time of my first comment).
--SA
Sergey Alexandrovich Kryukov 18-Jun-11 2:53am    
OP is recommended to formally accept this answer (green button).
--SA
Try to use int.TryParse function
 
Share this answer
 
Try that
<br />
int a = int.Parse(GridView1.Rows[i].Cells[0].Text);<br />
 
Share this answer
 
Comments
guptaadeepak 17-Jun-11 7:49am    
yes its right

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900