C# .NET - link between text boxes

Asked By David
02-Sep-10 11:41 PM
 suppose i have two text boxes one is for total and another for discount...
suppose whenever i enter value (10%) in the discount text box it should apply discount formula on the tota l(500)  and new value(450) again shoud remain in the total text box...
 for ex.  total is 500 and i entered value in discount 10 then the new result in total text box should be 450....
i am begineer in c#.. i tried many times ..but it is not working...plx suggest how to do that ....
any help would be appreciated...
  Shunmuga Nathan replied to David
03-Sep-10 01:38 AM
Try the following code

txtTotel.Text = ( Convert.ToDouble(txtTotel.Text) - ( Convert.ToDouble(txtTotel.Text) *  Convert.ToDouble(txtDiscount.Text) / 100)).ToString();
  Sagar P replied to David
03-Sep-10 03:14 AM
What you can do is, take one global static variable and store your total in that variable like;

static int total = 500;


And then on text changed event of Discount text box write this code;

private void txtDiscount_TextChanged(object sender, EventArgs e)

{

  if (txtDiscount.Text !="")

  {

    txtTotal.Text = (total - (total * Convert.ToDouble(txtDiscount.Text) / 100)).ToString();

  }

}



  Goniey N replied to David
04-Sep-10 08:33 AM
-- Use Below Code :

1.private void button1_Click(object sender, EventArgs e)
2.{
3.  txtTotal.Text = Convert.ToString(Convert.ToDouble(txtTotal.Text) - (Convert.ToDouble(txtTotal.Text) * Convert.ToDouble(txtDiscount.Text)) / 100);
4.}


-- For More Clear View See Below Images :

-- Before Click On The Calculate Button...




-- After Click On Calculate Button....




-- It Will Work 100%...

-- Hope This Help You...
Create New Account
help
public BalanceForm() { InitializeComponent(); } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { } private void button1_Click(object sender, EventArgs e) { } private void BalanceForm_FormClosing(object sender, FormClosingEventArgs e) { e.Cancel = true; this.Hide(); this.WindowState = FormWindowState.Normal; } private void BalanceForm_Load(object sender, EventArgs e) { this.dataGridView1.Rows.Add(34); this.dataGridView2.Rows.Add(35); this.dataGridView2.Rows[0 lt"; this.dataGridView2.Rows[34].Cells[1].Value = "mg / lt"; } private void BalanceForm_Activated(object sender, EventArgs e) { / / GASTO this.dataGridView1.Rows[0].Cells[0].Value = "Gasto"; this.dataGridView1.Rows[0].Cells Rows[1].Cells[1].Value = "m3 / dia"; this.dataGridView1.Rows[0].Cells[2].Value = Convert.ToDouble(this.dataGridView2.Rows[0].Cells[2].Value); this.dataGridView1.Rows[1].Cells[2].Value = (Convert.ToDouble(this.dataGridView1.Rows[0].Cells[2].Value) * 86400) / 1000; this.dataGridView1.Rows[0].Cells[17 Value = Lodos.Recirculacion1 * 0.05; this.dataGridView1.Rows[1].Cells[17].Value = Convert.ToDouble(this.dataGridView1.Rows[0].Cells[17].Value)*86400 / 1000; this.dataGridView1.Rows[0].Cells[3].Value = Gasto.Gastomedio1 + double.Parse(this.dataGridView1.Rows[0].Cells[17].Value.ToString()); this.dataGridView1.Rows[1].Cells[3].Value = Convert ToDouble(this.dataGridView1.Rows[0].Cells[3].Value) * 86400 / 1000; this.dataGridView1.Rows[0].Cells[5
string Hieght_Y = ""; public string Time = ""; / / - -- -- -- public int _Part = 0; #endregion protected void Page_Load(object sender, EventArgs e) { try { if (Session["UserId"] ! = null) { User_Id = Convert.ToInt32(Session["UserId"].ToString()); if (!IsPostBack) { / / LoadInitialSetting(); mvOA.ActiveViewIndex = 1; / / btnSave.Attributes.Remove("onclick"); btnSave.Enabled = false; hdnReadonly.Value Auto Generate Numbers Prod_Auto_number = "OA" + Auto_Generate_Number(2, 1000) + "Pd" + Auto_Generate_Number(3, 10000); txtGradeNumber.Text = Prod_Auto_number.ToString(); Part_Auto_number = "OA" + Auto_Generate_Number(3, 10000) + "Prt" + Auto_Generate_Number(2, 100000); txtGradeNumber_Parts.Text = Part_Auto_number.ToString(); Mat_Auto_number = "OA" + Auto_Generate_Number(4, 10000) + "Mat" + Auto_Generate_Number(3, 100000); txtGradeNumber_Mat.Text = Mat_Auto_number.ToString(); Part_Auto_number = "OA" + Auto_Generate_Number(2, 1000) + "PrtMat" + Auto_Generate_Number(3, 10000); txtGrade_Part_Mat.Text = Part_Auto_number ToString(); } ChkOA_Number_Availability.Attributes.Add("onclick", "if(!CheckOA_Number()) return false; "); btnCheckMaterial_grade.Attributes.Add("onclick", "if(!CheckGrade_Mat()) return _part_name) { try { List<object> ObjSpecifications = new List<object> (); ObjSpecifications = OAGeneration.Get_Part_Specifications_WebService(_part_name); Thickness = (ObjSpecifications[1].ToString().Split('-'))[1]; Width_X = (ObjSpecifications[2].ToString().Split('-'))[1]; Hieght_Y = (ObjSpecifications[3].ToString().Split('-'))[1]; Time = (ObjSpecifications[4].ToString().Split('-'))[1]; txtHeight_Part
encountered an exception when trying to access the setup state file: Could not find file 'C: \ ExchangeSetupLogs \ exchangeInstallState.xml'. [11 / 17 / 2011 19:11:40.0020] [0] Setup is determining what bin \ EnterpriseServiceEndpointsConfig.xml". [11 / 17 / 2011 19:14:14.0386] [1] Writing informational script to 'C: \ ExchangeSetupLogs \ Start-PreConfiguration-20111117-13141306991562273802.ps1' [11 / 17 / 2011 19:14:14.0386] [1] Executing 0417] [1] Executing: $RoleRoles = 'ClientAccessRole' [11 / 17 / 2011 19:14:14.0417] [1] Executing: $RoleSetupLoggingPath = 'C: \ ExchangeSetupLogs' [11 / 17 / 2011 19:14:14.0417] [1] Executing: $RoleTargetVersion = '14.01.0339.001 bin \ EnterpriseServiceEndpointsConfig.xml". [11 / 17 / 2011 19:15:28.0550] [1] Writing informational script to 'C: \ ExchangeSetupLogs \ Start-PreSetup-20111117-13152805501269886028.ps1' [11 / 17 / 2011 19:15:28.0550] [1] Executing 0550] [1] Executing: $RoleRoles = 'ClientAccessRole' [11 / 17 / 2011 19:15:28.0565] [1] Executing: $RoleSetupLoggingPath = 'C: \ ExchangeSetupLogs' [11 / 17 / 2011 19:15:28.0565] [1] Executing: $RoleTargetVersion = '14.01.0339.001 bin \ EnterpriseServiceEndpointsConfig.xml". [11 / 17 / 2011 19:15:28.0706] [1] Writing informational script to 'C: \ ExchangeSetupLogs \ Start-PreFileCopy-20111117-13152807061586562721.ps1' [11 / 17 / 2011 19:15:28.0706] [1] Executing 0706] [1] Executing: $RoleRoles = 'ClientAccessRole' [11 / 17 / 2011 19:15:28.0706] [1] Executing: $RoleSetupLoggingPath = 'C: \ ExchangeSetupLogs' [11 / 17 / 2011 19:15:28.0706] [1] Executing: $RoleTargetVersion = '14.01.0339.001 0}, {1}, {2}", $_.Id, $_.Process, $_.Module); $sb.AppendLine(); }; Write-ExchangeSetupLog -Info $sb.ToString(); [11 / 17 / 2011 19:15:28.0721] [2] Listing all processes and the files held
encountered an exception when trying to access the setup state file: Could not find file 'C: \ ExchangeSetupLogs \ exchangeInstallState.xml'. [11 / 17 / 2011 19:11:40.0020] [0] Setup is determining what bin \ EnterpriseServiceEndpointsConfig.xml". [11 / 17 / 2011 19:14:14.0386] [1] Writing informational script to 'C: \ ExchangeSetupLogs \ Start-PreConfiguration-20111117-13141306991562273802.ps1' [11 / 17 / 2011 19:14:14.0386] [1] Executing 0417] [1] Executing: $RoleRoles = 'ClientAccessRole' [11 / 17 / 2011 19:14:14.0417] [1] Executing: $RoleSetupLoggingPath = 'C: \ ExchangeSetupLogs' [11 / 17 / 2011 19:14:14.0417] [1] Executing: $RoleTargetVersion = '14.01.0339.001 bin \ EnterpriseServiceEndpointsConfig.xml". [11 / 17 / 2011 19:15:28.0550] [1] Writing informational script to 'C: \ ExchangeSetupLogs \ Start-PreSetup-20111117-13152805501269886028.ps1' [11 / 17 / 2011 19:15:28.0550] [1] Executing 0550] [1] Executing: $RoleRoles = 'ClientAccessRole' [11 / 17 / 2011 19:15:28.0565] [1] Executing: $RoleSetupLoggingPath = 'C: \ ExchangeSetupLogs' [11 / 17 / 2011 19:15:28.0565] [1] Executing: $RoleTargetVersion = '14.01.0339.001 bin \ EnterpriseServiceEndpointsConfig.xml". [11 / 17 / 2011 19:15:28.0706] [1] Writing informational script to 'C: \ ExchangeSetupLogs \ Start-PreFileCopy-20111117-13152807061586562721.ps1' [11 / 17 / 2011 19:15:28.0706] [1] Executing 0706] [1] Executing: $RoleRoles = 'ClientAccessRole' [11 / 17 / 2011 19:15:28.0706] [1] Executing: $RoleSetupLoggingPath = 'C: \ ExchangeSetupLogs' [11 / 17 / 2011 19:15:28.0706] [1] Executing: $RoleTargetVersion = '14.01.0339.001 0}, {1}, {2}", $_.Id, $_.Process, $_.Module); $sb.AppendLine(); }; Write-ExchangeSetupLog -Info $sb.ToString(); [11 / 17 / 2011 19:15:28.0721] [2] Listing all processes and the files held
Text = = "All" && CheckBoxList1.SelectedIndex = = -1) { cmd = new SqlCommand ( "select a.img, a.prop_name, b.state_name, c.city_name, d.price, d.prop_price_type, d.builtup_area, d.carpet_area, d.bedrooms, d.prop_desc, e.ownership_name from tbl_image_entry a, tbl_state_new b, tbl_city_new c, tbl_new_sale_property d, tbl_ownership_master e where a.user_id = d.user_id and b.state_id = d.state and c.city_id = d.city and a.prop_name = d.prop_name and e.ownership_id = d.prop_ownership and prop_type CheckBoxList1.Items[2].Selected = = false ) { cmd = new SqlCommand ( "select a.img, a.prop_name, b.state_name, c.city_name, d.price, d.prop_price_type, d.builtup_area, d.carpet_area, d.bedrooms, d.prop_desc, e.ownership_name from tbl_image_entry a, tbl_state_new b, tbl_city_new c, tbl_new_sale_property d, tbl_ownership_master e where a.user_id = d.user_id and b.state_id = d.state and c.city_id = d.city and a.prop_name = d.prop_name and e.ownership_id = d.prop_ownership and prop_ownership CheckBoxList1.Items[2].Selected = = false ) { cmd = new SqlCommand ( "select a.img, a.prop_name, b.state_name, c.city_name, d.price, d.prop_price_type, d.builtup_area, d.carpet_area, d.bedrooms, d.prop_desc, e.ownership_name from tbl_image_entry a, tbl_state_new b, tbl_city_new c, tbl_new_sale_property d, tbl_ownership_master e where a.user_id = d.user_id and b.state_id = d.state and