Click here to Skip to main content
15,919,341 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have tried this code to get cell value from gridview but while debugging it is giving error please help

What I have tried:

studu = Convert.ToInt16(e.Row.Cells[0].Text);
Posted
Updated 3-May-18 6:09am

Check that the cell actually has a value and is not empty and that the cell contains a string that can actually be converted (numeric characters and minus sign only).
 
Share this answer
 
based on the error message, it possible that the value in e.Row.Cells[0].Text could be null or empty or not a valid number string. I suggest to use int.Tryparse method, see below as an example.

C#
int number;

         bool result = Int32.TryParse(e.Row.Cells[0].Text, out number);
		
		
		if (result) {
			Console.WriteLine("aiyeee baaa");
		}
		else {
			Console.WriteLine("booo");	
		}
 
Share this answer
 

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