Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 13th, 2007, 12:42 PM
Authorized User
Join Date: Feb 2007
Location: Bend, Oregon, USA.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sum Textbox Values

I have approximately 15 textboxes that I want to sum together.

I have tried textbox1.Text + Textbox2.Text but this just concatenates the numbers together.

I can get this to work by creating mulitple variables of type integer and then setting each textbox value as a seperate variable and then adding the variables together but this seems excessive.
Reply With Quote
  #2 (permalink)  
Old April 13th, 2007, 01:36 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

You need to cast the .Text value to an integer. There's nothing excessive about that. That's what you get with a strongly typed language.

Maybe to make it a bit easier to write and run, you could add all the textboxes to a generic list:

   List<TextBox> lstTextBoxes = new List<TextBox>();

then loop thru the list to add everything up:

   int intTotal = 0;
   for(int i = 0; i < lstTextBoxes.Count; i++){
      intTotal += int.Parse(lstTextBoxes[i].Text);

Of course, you'll want to catch formatting errors and such.

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get the Sum of all the values in a column.. jhansib4u ADO.NET 1 December 1st, 2007 09:15 PM
How Do I Sum Numbers In a TextBox wb8bgy Visual Basic 2005 Basics 1 December 10th, 2005 01:29 PM
Need help to write codes to sum values sunny76 Excel VBA 1 July 6th, 2005 05:05 AM
SUM with formula values SiliconFuRy Excel VBA 3 January 7th, 2005 08:17 AM
Sum values by key Justine Oracle 1 April 28th, 2004 03:12 PM

All times are GMT -4. The time now is 08:16 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.