c#菜鸟问题 两个文本框,textchange促发事件,当两个文本框中都为数字时两者相乘放到第三个文本框,求代码.... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 前台<div> <asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged" AutoPostBack="true "></asp:TextBox> * <asp:TextBox ID="TextBox2" runat="server" OnTextChanged="TextBox2_TextChanged" AutoPostBack="true "></asp:TextBox> = <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> </div>cs页面namespace WebApplication2{ public partial class test1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } int num1 = 0; int num2 = 0; protected void TextBox1_TextChanged(object sender, EventArgs e) { if (!string.IsNullOrEmpty(TextBox1.Text.Trim())) { num1 = ConvertStringToInteger(TextBox1.Text.Trim()); } if (!string.IsNullOrEmpty(TextBox2.Text.Trim())) { num2 = ConvertStringToInteger(TextBox2.Text.Trim()); } TextBox3.Text = (num1 * num2).ToString(); } protected void TextBox2_TextChanged(object sender, EventArgs e) { if (!string.IsNullOrEmpty(TextBox1.Text.Trim())) { num1 = ConvertStringToInteger(TextBox1.Text.Trim()); } if (!string.IsNullOrEmpty(TextBox2.Text.Trim())) { num2 = ConvertStringToInteger(TextBox2.Text.Trim()); } TextBox3.Text = (num1 * num2).ToString(); } private static int ConvertStringToInteger(string s) { int result = 0; int.TryParse(s, out result); return result; } }} <div> <asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged" AutoPostBack="true "></asp:TextBox> * <asp:TextBox ID="TextBox2" runat="server" OnTextChanged="TextBox2_TextChanged" AutoPostBack="true "></asp:TextBox> = <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> </div>namespace WebApplication2{ public partial class test1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } int num1 = 0; int num2 = 0; protected void TextBox1_TextChanged(object sender, EventArgs e) { num1 = ConvertStringToInteger(TextBox1.Text.Trim()); num2 = ConvertStringToInteger(TextBox2.Text.Trim()); TextBox3.Text = (num1 * num2).ToString(); } protected void TextBox2_TextChanged(object sender, EventArgs e) { num1 = ConvertStringToInteger(TextBox1.Text.Trim()); num2 = ConvertStringToInteger(TextBox2.Text.Trim()); TextBox3.Text = (num1 * num2).ToString(); } private static int ConvertStringToInteger(string s) { int result = 0; int.TryParse(s, out result); return result; } }} 在窗体中摆三个TextBox,分别叫做txt被乘数,txt乘数,txt积……using System;using System.Windows.Forms;namespace WindowsFormsApplication1{ public partial class Form1 : Form { public Form1() { InitializeComponent(); this.txt被乘数.TextChanged += new EventHandler(被乘数或乘数_TextChanged);// 改变被乘数时触发事件 this.txt乘数.TextChanged += new EventHandler(被乘数或乘数_TextChanged);// 改变乘数时触发事件 } void 被乘数或乘数_TextChanged(object sender, EventArgs e) { try { decimal 被乘数 = Convert.ToDecimal(this.txt被乘数.Text); decimal 乘数 = Convert.ToDecimal(this.txt乘数.Text); this.txt积.Text = (被乘数 * 乘数).ToString(); } catch { this.txt积.Text = string.Empty; } } }} TextChange中看两个文本框中是不是有值,且是数字,是的话相乘赋值就完了呗! 算法问题 C#动态调用dll的方法? 如何实现WEB页面对话框 c#中static干什么用的? 从MemberShip 的角色推出用户 哪位大哥有nurbs曲线的c#代码? c# 写的 WINCE 程序,如何做到反编译 怎样将word文件读入到richtextbox? 各位好,我有一些关于DATAGRID的问题想请教一下 today,用visual c# 写了一个 分析IP网关log的东西 C#事务处理疑问 怎么向Word或ppt里面插入视频文件(C#代码)
<asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged" AutoPostBack="true "></asp:TextBox>
*
<asp:TextBox ID="TextBox2" runat="server" OnTextChanged="TextBox2_TextChanged" AutoPostBack="true "></asp:TextBox>
=
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</div>cs页面namespace WebApplication2
{
public partial class test1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
int num1 = 0;
int num2 = 0;
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(TextBox1.Text.Trim()))
{
num1 = ConvertStringToInteger(TextBox1.Text.Trim());
}
if (!string.IsNullOrEmpty(TextBox2.Text.Trim()))
{
num2 = ConvertStringToInteger(TextBox2.Text.Trim());
}
TextBox3.Text = (num1 * num2).ToString();
} protected void TextBox2_TextChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(TextBox1.Text.Trim()))
{
num1 = ConvertStringToInteger(TextBox1.Text.Trim());
}
if (!string.IsNullOrEmpty(TextBox2.Text.Trim()))
{
num2 = ConvertStringToInteger(TextBox2.Text.Trim());
}
TextBox3.Text = (num1 * num2).ToString();
} private static int ConvertStringToInteger(string s)
{
int result = 0;
int.TryParse(s, out result);
return result;
}
}
}
<div>
<asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged" AutoPostBack="true "></asp:TextBox>
*
<asp:TextBox ID="TextBox2" runat="server" OnTextChanged="TextBox2_TextChanged" AutoPostBack="true "></asp:TextBox>
=
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</div>namespace WebApplication2
{
public partial class test1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
int num1 = 0;
int num2 = 0;
protected void TextBox1_TextChanged(object sender, EventArgs e)
{ num1 = ConvertStringToInteger(TextBox1.Text.Trim());
num2 = ConvertStringToInteger(TextBox2.Text.Trim());
TextBox3.Text = (num1 * num2).ToString();
} protected void TextBox2_TextChanged(object sender, EventArgs e)
{
num1 = ConvertStringToInteger(TextBox1.Text.Trim());
num2 = ConvertStringToInteger(TextBox2.Text.Trim());
TextBox3.Text = (num1 * num2).ToString();
} private static int ConvertStringToInteger(string s)
{
int result = 0;
int.TryParse(s, out result);
return result;
}
}
}
using System;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.txt被乘数.TextChanged += new EventHandler(被乘数或乘数_TextChanged);// 改变被乘数时触发事件
this.txt乘数.TextChanged += new EventHandler(被乘数或乘数_TextChanged);// 改变乘数时触发事件
} void 被乘数或乘数_TextChanged(object sender, EventArgs e)
{
try
{
decimal 被乘数 = Convert.ToDecimal(this.txt被乘数.Text);
decimal 乘数 = Convert.ToDecimal(this.txt乘数.Text);
this.txt积.Text = (被乘数 * 乘数).ToString();
}
catch
{
this.txt积.Text = string.Empty;
}
}
}
}