我如何在ASP.NET中进行简单的计算 [英] How do I do simple calculations in ASP.NET

查看:70
本文介绍了我如何在ASP.NET中进行简单的计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算一个加权平均值。每项任务分别为10%,中期30%和最终40%:



I want to calculate a weighted average. Each assignment weighs 10%, midterm 30%, and final 40% for the following:

<script runat="server">
Sub submit(sender As Object, e As EventArgs)
lbl3.Text="Grade on Assignment 1: " & txt1.Text
lbl4.Text="Grade on Assignment 2: " & txt2.Text
lbl5.Text="Grade on Assignment 3: " & txt3.Text
lbl6.Text="Grade on Midterm: " & txt4.Text
lbl7.Text="Grade on Final: " & txt5.Text
lbl8.Text="Weighted Average: " & txt7.Text
txt1.Text=""
End Sub
</script>

<html>
<body><form runat="server">
Enter your grades for the following assessments:
<p>Assignment 1: <asp:TextBox id="txt1" runat="server" /></p>
<p>Assignment 2: <asp:TextBox id="txt2" runat="server" /></p>
<p>Assignment 3: <asp:TextBox id="txt3" runat="server" /></p>
<p>Midterm: <asp:TextBox id="txt4" runat="server" /></p>
<p>Final: <asp:TextBox id="txt5" runat="server" /></p>
<asp:Button OnClick="submit" Text="Submit" runat="server" />

<p><asp:Label id="lbl1" runat="server" /></p>
<p><asp:Label id="lbl2" runat="server" /></p>
<p><asp:Label id="lbl3" runat="server" /></p>
<p><asp:Label id="lbl4" runat="server" /></p>
<p><asp:Label id="lbl5" runat="server" /></p>
</form></body>
</html>





我知道如何使用<%Response.Write(result)%> 在asp中进行算术运算,如下所示:





I know how to do arithmetic in asp using <% Response.Write(result) %> as follows:

<% Dim A,B,C, result
A = request.form("txt1")
B = request.form("txt2")
C = request.form("txt3")
D = request.form("txt4")
E = request.form("txt5")
''Use CInt() to convert A,B, C to integer type
result = CInt(A)*.10+CInt(B)*.10+CInt(C)*.10+CInt(D)*.30+CInt(E)*.40
''Use CDbl() to convert result to double type
%>
<p>Your calculated grade is  <% Response.Write (result) %></P>





我想执行相同的操作,但是在asp.net中。我该怎么做?



I want to perform the same exact operation, but in asp.net. How do I do this?

推荐答案

有没有听说过关注点分离?计算是计算,它们不取决于应用程序是什么,ASP.NET与否。这个问题毫无意义。



-SA
Ever heard of separation of concerns? Calculations are calculations, they do not depends on what is the application, ASP.NET or not. The question makes no sense at all.

—SA


这篇关于我如何在ASP.NET中进行简单的计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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