如何计算输入单个文本框的多个总和 [英] How to calculate the sum of more than one entered into a single textbox

查看:103
本文介绍了如何计算输入单个文本框的多个总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!



我有下载列表控件,其中包含asp.net C#中的主题。用户从下拉列表中选择主题说数学,然后在文本框中输入主题的标记。点击提交按钮将数据存储在数据库中,我想返回输入标记的总数说,我输入3个不同的标记我如何得到总数。



i尝试



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

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



但是显示的总数db中输入的数字乘以公式中的(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

推荐答案

使用以下行来获取所有主题的总和...在您的点击事件中..



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



否则将每个主题及其标记存储到一个集合中,以便您可以在其他方法中重复使用它...

字典<字符串,> dicSubject = new Dictionary< string,long>();

dicSubject.Add(Maths,40);





然后

遍历集合以获得标记的总和。
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.


这篇关于如何计算输入单个文本框的多个总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆