Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi!

I have dropdownlist control that contain subjects in asp.net C# . The user selects the subject say maths, from the dropdownlist and then enter the mark for the subject in the textbox. Click on submit button to store the data in the database, i want to return the total of the entered marks say, i entered 3 different marks how do i get the total.

i tried

C#
double total = Convert.ToDouble(TextBox95.Text);
        
           total = Convert.ToInt32(TextBox93.Text) + Convert.ToInt32(TextBox93.Text)----

but the displayed total in db is the entered number multiplied by the number of (Convert.ToInt32(TextBox93.Text))in the formula. it makes sense mathematically but how do i make the entered values appear differently while stored in the same textbox?

thank you
Posted
Comments
[no name] 25-Jun-13 17:57pm    
Not that you are going to bother but "how do i make the entered values appear differently while stored in the same textbox", what does that even mean?
MuhammadUSman1 26-Jun-13 0:04am    
Couldn't understand what exactly you want to do?
BulletVictim 26-Jun-13 1:31am    
You are looking for something more like this?
total = double.Parse(textBox1.Text) + double.Parse(textBox2.Text);

1 solution

use the following line to get sum of all subjects...In your click event ..

total=total+Convert.ToInt32(TextBox93.Text);

Else store each subject and its mark to a collection so that you can reuse it in other methods also...
Dictionary<string,> dicSubject=new Dictionary< string,long>();
dicSubject.Add("Maths",40);


Then
Iterate through the collection to get sum of the marks.
 
Share this answer
 
v3
Comments
BulletVictim 26-Jun-13 1:55am    
Sadique that method works better when the total is calculated within a loop.
Now not saying its wrong. Depending on how he intends to write the total to the database

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