asp.net中文本框值的总和 [英] sum of textbox values in asp.net

查看:59
本文介绍了asp.net中文本框值的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

asp.net中的文本框值的总和。这是我的代码



sum of textbox values in asp.net.This is My Code

decimal num = Convert.ToDecimal(txtcustomot.Text);
         decimal num2 = Convert.ToDecimal(txtAirfreight.Text);
         decimal num3 = Convert.ToDecimal(txtDocument.Text);
         decimal num4 = Convert.ToDecimal(txtcompt.Text);
         decimal num5 = Convert.ToDecimal(txtairlanka.Text);
         decimal num6 = Convert.ToDecimal(txtcexp.Text);
         decimal num8 = num + num2 + num3 + num4 + num5 + num6;
         lbltotal0.Text = num8.ToString();





我想处理空值Textbox.exsample txtcustomot.Text是null代码不工作如何解决这个问题。任何人都可以帮助我,



谢谢



如何传递空值存储过程

参数[1] .Value = Decimal.Parse(txtAirfreight.Text);



此代码不能正常工作。



I want to handle null value Textbox.exsample txtcustomot.Text is null code not working how to fix this one.any one can help me,

Thank You

How to pass the null value store procedure
parameters[1].Value = Decimal.Parse(txtAirfreight.Text);

This code is not working.

推荐答案

试试这个

try this
decimal num =0,num2=0,num3=0,num4=0,num5=0,num6=0;
         decimal.TryParse(txtcustomot.Text,out num);
         decimal.TryParse(txtAirfreight.Text,out num2);
         decimal.TryParse(txtDocument.Text,out num3);
         decimal.TryParse(txtcompt.Text,out num4);
         decimal.TryParse(txtairlanka.Text,out num5);
         decimal.TryParse(txtcexp.Text,out num6);
         decimal num8 = num + num2 + num3 + num4 + num5 + num6;
         lbltotal0.Text = num8.ToString();


不要使用Convert:use decimal.TryParse:

Don't use Convert: use decimal.TryParse instead:
decimal num;
decimal.TryParse(txtcustomot.Text, out num);

如果失败,它将在 num 变量中保留零(并返回false,以便在必要时报告问题)

If it fails, it will leave zero in the num variable (and return false, so you could report a problem if necessary)


嘿那里,



你可以尝试这个例子用于你的所有十进制变量赋值:
Hey there,

You could try this example for all your decimal variable assignments:
String.IsNullOrEmpty(txtAirfreight.Text.Trim()) ? 0 : Convert.ToDecimal( txtAirfreight.Text.Trim());

以避免异常。



希望它有帮助



Azee ......

to avoid the Exception.

Hope it helps

Azee...


这篇关于asp.net中文本框值的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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