asp.net中动态控件使用
程序员文章站
2023-12-28 11:40:40
...
动态控件添加:
TextBox _txt;
int i =0;
try
{
i = Int32.Parse(TextBox1.Text);
}
catch{}
if (i > 0)
{
for (int _i = 1; _i < i; _i++)
{
_txt = new TextBox();
_txt.Text = _i.ToString();
Panel1.Controls.Add(_txt);
}
}
动态控件操作:
double _dSum = 0;
TextBox _txt;
foreach (Control _ctl in Panel1.Controls)
{
if (_ctl is TextBox)
{
_txt = (TextBox)_ctl;
_dSum += double.Parse(_txt.Text);
}
System.Diagnostics.Debug.Write("1" + _dSum.ToString());
}
System.Diagnostics.Debug.Write(_dSum.ToString());
Button2.Text = _dSum.ToString();