如何默认添加文本框值 [英] how to defaultly add textbox values

查看:92
本文介绍了如何默认添加文本框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我需要默认添加文本框值


对此,按照sql语句的一个疑问,所有字段都必须是需要的值.如果一个字段值未输入valur,则会在错误消息中显示.如何解决此错误.

Dear All,

i need add the text box values defaultly


one doubt for this as per in sql statement, all fields must be need values. if one field value not enter valur show in error message. how to resolve this error.

txtOSITotalIncome.Text =  txtOSIInterstFromBank.Text + txtOSIInterestFromDebent.Text+txtOSIAccuredInterstOnNSC.Text
txtOSITotalTDS.Text = txtOSITDSFromBank.Text+ txtOSIAccuredInterstOnNSC.Text



如何在文本框中获取这些总和



how to get the these sums in textboxes

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class OtherSourceIncome : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void btnOSI_Save_Click(object sender, EventArgs e)
    {
        string connection = System.Configuration.ConfigurationManager.ConnectionStrings["itax"].ConnectionString;
        SqlConnection con = new SqlConnection(connection);
        try
        {
            con.Open();
            SqlCommand cmd = new SqlCommand("INSERT INTO other_source_income VALUES ('" + txtOSIInterstFromBank.Text + "','"
            + txtOSITDSFromBank.Text + "','"
            + txtOSIInterestFromDebent.Text + "','"
            + txtOSITDSFromNSSWithdr.Text + "','"
            + txtOSIAccuredInterstOnNSC.Text + "','"
            + txtOSITotalIncome.Text + "','"
            + txtOSITotalTDS.Text + "','"
            + txtOSISalary.Text + "','"
            + txtOSIProfessionalTax.Text + "','"
            + txtOSIPFDeduction.Text + "','"
            + txtOSITDS.Text + "')", con);

            cmd.ExecuteNonQuery();
        }
}

推荐答案

使用javascript来计算值.

这是利用此示例.我用过
txtsubject1
txtsubject2
txtsubject3

计算txtTotal.

我在文本框中使用了onBlur事件,以便当焦点从文本框中移出时,将调用calculate函数.

这是我在aspx页面中的代码.

Make use of javascript to calculate the values.

Here is piece of example make use of this. i have used
txtsubject1
txtsubject2
txtsubject3

to calculate txtTotal.

I have used the onBlur event in the textbox so that when the focus is out from the textbox the calculate function will be called.

This is my code in aspx page.

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
    <script type = "text/javascript">
        //This is the javascript function which will calulate the total
        function calculate() {

            var sub1 = document.getElementById('txtSubject1').value; // specify the subject1 text box id value
            var sub2 = document.getElementById('txtSubject2').value; // specify the subject2 text box id value
            var sub3 = document.getElementById('txtSubject3').value; // specify the subject3 text box id value

            if (sub1 == '') sub1 = 0;
            if (sub2 == '') sub2 = 0;
            if (sub3 == '') sub3 = 0;

            var total = parseInt(sub1) + parseInt(sub2) + parseInt(sub3);

            document.getElementById('txtTotal').value = total;
        }

    </script>
</head>
<body onload="OnSuccess();">
    <form id="form1" runat="server">

        <asp:Panel runat="server" id="Panel2" style="display:block; width:718px;" >

        <tr>
        <tr>
        <td class="style1" style="width: 281px"> subject1:
        <asp:TextBox ID="txtSubject1" runat="server" onBlur="return calculate();" ></asp:TextBox>
        </td>
        <td style="width: 458px">
            <br />
            subject2:
        <asp:TextBox ID="txtSubject2" runat="server" onBlur="return calculate();" ></asp:TextBox>
        </td>
        <td style="width: 458px">
            <br />
            subject3:
        <asp:TextBox ID="txtSubject3" runat="server" onBlur="return calculate();" ></asp:TextBox>
        </td>
        <td style="width: 458px">
            <br />
            Total:
        <asp:TextBox ID="txtTotal" runat="server"></asp:TextBox>
        </td>
        </tr>
        </td>
            </tr>

        </asp:Panel>

    </form>
</body>
</html>


这篇关于如何默认添加文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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