使用C#在ASP.Net中自动计算 [英] Auto Calculate in ASP.Net using C#

查看:80
本文介绍了使用C#在ASP.Net中自动计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户是否可以将数据输入文本框,然后使用Tab键切换到下一个文本框,以便自动计算数字。如果用户在textbox1中输入25并且数学公式为* / 5 =,则在textbox2中答案为5.是否有办法在C#中执行此操作?



Is there a way for a user to enter data into a textbox and then tab to the next textbox for it to auto calculate the numbers. If a user enters 25 in textbox1 and the math formula is */5 =, then in textbox2 the answer will be 5. Is there a way of doing this in C#?

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Drawing;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Data.SqlClient;
using System.Configuration;
using System.Drawing.Printing;
using System.Web.SessionState;

public partial class FinancialProfileFormD : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ButtonPrint.Attributes.Add("onclick", "window.print(); return false");

       SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
       con.Open();

       SqlConnection con2 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
       con2.Open();

       TextBoxINST_ID.Text = Session["inst_id"].ToString();
       SqlCommand scmd = new SqlCommand("Select INST_ID, LongName, City, State from TableCOCINST where INST_ID = '" + TextBoxINST_ID.Text + "'", con);
       SqlCommand scmd2 = new SqlCommand("Select INST_ID, INSTRUCTIO, RESEARCH, ACADEMIC_S, NET_AID, AUXILIARY_, OTHEREXP, TOTASSETS, TOTLIABILITY, NoNEXPPERMRESASSETS, UNRNETASSETS, TOTALREV, TUITFEES, CURRDEBT, LONGTERMDEBT from TableFIN2012 where INST_ID = '" + TextBoxINST_ID.Text + "'", con2);
       SqlDataReader dr = scmd.ExecuteReader();
       SqlDataReader dr2 = scmd2.ExecuteReader();
        if (dr.Read())
        if (dr2.Read())
            {
            lblSchool2.Text = dr["LongName"].ToString();
            lblSchool.Text = dr["LongName"].ToString();
            lblCity.Text = dr["City"].ToString();
            lblState.Text = dr["State"].ToString();
            TextBoxLYInstr.Text = dr2["INSTRUCTIO"].ToString();
            TextBoxLYResPs.Text = dr2["RESEARCH"].ToString();
            TextBoxLYAcadSSSIS.Text = dr2["ACADEMIC_S"].ToString();
            TextBoxLYAuxE.Text = dr2["AUXILIARY_"].ToString();
            TextBoxLYNGAS.Text = dr2["NET_AID"].ToString();
            TextBoxLYAOE.Text = dr2["OTHEREXP"].ToString();
            TextBoxLYTA.Text = dr2["TOTASSETS"].ToString();
            TextBoxLYTL.Text = dr2["TOTLIABILITY"].ToString();
            TextBoxLYNPRNA.Text = dr2["NoNEXPPERMRESASSETS"].ToString();
            TextBoxLYTUNA.Text = dr2["UNRNETASSETS"].ToString();
            TextBoxLYTR.Text = dr2["TOTALREV"].ToString();
            TextBoxLYTFN.Text = dr2["TUITFEES"].ToString();
            TextBoxLYCD.Text = dr2["CURRDEBT"].ToString();
            TextBoxLYLTD.Text = dr2["LONGTERMDEBT"].ToString();
            
        }
        dr.Close();
        con.Close();
        dr2.Close();
        con2.Close();
    }
    
    protected void ButtonSubmit_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);


        SqlCommand cmd = new SqlCommand ("Insert into TableFIN2013 (INST_ID, TOTAL_REVE, INSTRUCTIO, RESEARCH, ACADEMIC_S, NET_AID, AUXILIARY_, OTHEREXP, TOTASSETS, TOTLIABILITY, NoNEXPPERMRESASSETS, UNRNETASSETS, TOTALREV, TUITFEES, CURRDEBT, LOMGTERMDEBT) values (@INST_ID, @TOTAL_REVE, @INSTRUCTIO, @RESEARCH, @ACADEMIC_S, @NET_AID, @AUXILIARY_, @OTHEREXP, @TOTASSETS, @TOTLIABILITY, @NoNEXPPERMRESASSETS, @UNRNETASSETS, @TOTALREV, @TUITFEES, @CURRDEBT, @LOMGTERMDEBT)", con);

        cmd.CommandType = CommandType.Text;

        cmd.Parameters.AddWithValue("@INST_ID", TextBoxINST_ID);
        cmd.Parameters.AddWithValue("@TOTAL_REVE", TextBoxTR);
        cmd.Parameters.AddWithValue("@INSTRUCTIO", TextBoxInstr.Text);
        cmd.Parameters.AddWithValue("@RESEARCH", TextBoxResPs.Text);
        cmd.Parameters.AddWithValue("@ACADEMIC_S", TextBoxAcadSSSIS.Text);
        cmd.Parameters.AddWithValue("@NET_AID", TextBoxNGAS.Text);
        cmd.Parameters.AddWithValue("@AUXILIARY_", TextBoxAuxE.Text);
        cmd.Parameters.AddWithValue("@OTHEREXP", TextBoxAOE.Text);
        cmd.Parameters.AddWithValue("@TOTASSETS", TextBoxTA.Text);
        cmd.Parameters.AddWithValue("@TOTLIABILITY", TextBoxTL.Text);
        cmd.Parameters.AddWithValue("@NoNEXPPERMRESASSETS", TextBoxNPRNA.Text);
        cmd.Parameters.AddWithValue("@EXPENDABLE", TextBoxETRNA.Text);
        cmd.Parameters.AddWithValue("@UNRNETASSETS", TextBoxTUNA.Text);
        cmd.Parameters.AddWithValue("@TOTALREV", TextBoxTR.Text);
        cmd.Parameters.AddWithValue("@TUITFEES", TextBoxTFN.Text);
        cmd.Parameters.AddWithValue("@CURRDEBT", TextBoxCD.Text);
        cmd.Parameters.AddWithValue("@LOMGTERMDEBT", TextBoxLTD.Text);

        
        cmd.ExecuteNonQuery();
        con.Close();
        Response.Redirect("FinancialProfileFormD.aspx");
        

    }
    protected void ButtonPrint_Click(object sender, EventArgs e)
    {

    }
    
   }

推荐答案

设置Textbox1 Autopostback = true



Set Textbox1 Autopostback=true

protected void textbox1_TextChanged(object sender, EventArgs e)
 {

   int i=Convert.ToInt32(textbox1.Text);
   int j=5;
   TextBox2.Text =Convert.ToString( i / j);

 }


这篇关于使用C#在ASP.Net中自动计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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