convert string to an integer

Posted on 2008-11-11
Last Modified: 2013-12-17
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

Question by:CharlieDev
    LVL 17

    Expert Comment

    by:Shanmuga Sundaram
    Haven't you tried using int.parse?

    Author Comment

    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!!!

    Author Comment

    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"
    LVL 15

    Accepted Solution

    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());

    Author Closing Comment

    Thanks for that :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Suggested Solutions

    Title # Comments Views Activity
    C# ConsolApp opens new window 16 43
    Help file 1 28
    Gridview Edit Row 10 33
    How can i Install a new Data Source on Visual Studio 2 51
    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now