Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
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.

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


how to get the these sums in textboxes

C#
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();
        }
}
Posted
Updated 11-May-12 5:20am
v3
Comments
jdarknight 11-May-12 5:26am    
Is this your problem?

You want to automatically calculate the values for txtOSITotalIncome , txtOSITotalTDS if some other text box's values are entered.
2011999 11-May-12 5:28am    
yes

1 solution

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.

XML
<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>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900