SIGN UP MEMBER LOGIN:    
ARTICLE

Total in TextBox of two TextBoxes in C#

Posted by Vilas Gite Articles | C# Language April 10, 2011
How to use Total in TextBox in two TextBoxes in C#.
Reader Level:



TextBox.gif

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsApplication10
{
    public partial class Form1 : Form
    {
        SqlConnection con = new SqlConnection();
        DataTable dt;
        DataRow dr;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'tRAILDataSet.CAL_TABLE' table. You can move, or remove it, as needed.
            this.cAL_TABLETableAdapter.Fill(this.tRAILDataSet.CAL_TABLE);
            textBox1.Enabled = false;
            textBox2.Enabled = false;
            textBox3.Enabled = false;
            btnSave.Enabled = false;
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            btnSave.Enabled = true;
            textBox1.Enabled = true;
            textBox2.Enabled = true;
            textBox3.Enabled = true;

            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";

            btnAdd.Enabled = false;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            int a = Convert.ToInt32(textBox1.Text);
            int k = Convert.ToInt32(textBox2.Text);
            int uItem1Tot = a + k;
            textBox3.Text = uItem1Tot.ToString();

            dt = tRAILDataSet.Tables["CAL_TABLE"];
          
            dr = dt.NewRow();
 
            dr[0] = textBox1.Text;
            dr[1] = textBox2.Text;
            dr[2] = textBox3.Text;

            dt.Rows.Add(dr);

            cAL_TABLETableAdapter.Update(tRAILDataSet.CAL_TABLE);

            textBox1.Enabled = false;
            textBox2.Enabled = false;
            textBox3.Enabled = false;

            btnAdd.Enabled = true;
            btnSave.Enabled = false;
 
        }
    }
}

Login to add your contents and source code to this article
share this article :
post comment
 

Nice job thanks

Posted by surender bhyan Apr 11, 2011
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Gauge for SharePoint
Become a Sponsor