convert string to an integer

I have a gridview table and i want to get the total of one of the columns. I need to convert the string thats in the field into an integer to add it up.
Can anyone suggest how i change this  " float.Parse(cells[cells.Count - 1].Text.Split(' ')[0]) ;  " so that
the total will be an integer.


int total;
    public void sumRows(Object src, GridViewRowEventArgs e)
        if (e.Row.RowType == DataControlRowType.DataRow)
            TableCellCollection cells = e.Row.Cells;
            total += float.Parse(cells[cells.Count - 1].Text.Split(' ')[0]) ; 
            cells[cells.Count - 1].Text = string.Format("{0:n}",
            float.Parse(cells[cells.Count - 1].Text.Split(' ')[0]));

Open in new window

Who is Participating?
angus_young_acdcConnect With a Mentor Commented:
Thats because part of what you're trying to convert isn't a string.  

Try the following:
float.Parse(cells[cells.Count - 1].Text.Split(' ')[0]).ToString());
Shanmuga SundaramDirector of Software EngineeringCommented:
Haven't you tried using int.parse?
CharlieDevAuthor Commented:
I dont know where to put it in my code, i'm trying to figure out where to put it now. Any suggestions be great!!!
CharlieDevAuthor Commented:
I'm trying '  total += Int32.Parse(float.Parse(cells[cells.Count - 1].Text.Split(' ')[0])) ;  '
but  i get an error   " The best overloaded method match for 'int.Parse(string)' has some invalid arguments"
CharlieDevAuthor Commented:
Thanks for that :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.