foreach (Control control in Controls)
{
TextBox tb = (TextBox)control;
tb.Text = "";
}
好像这样就行了吧!
我也记得不是很清楚了!
{
TextBox tb = (TextBox)control;
tb.Text = "";
}
好像这样就行了吧!
我也记得不是很清楚了!
解决方案 »
- 怎么在web页面修改Web.config的内容
- 问关于web自定义控件
- button事件中用代码如何实现关闭子窗口同时刷新父窗口
- CRM怎样做成模块式的
- 请问如何实现两个WebForm间的数据传送
- 急救!!IIS6.0配置问题!!!(高手进)散分了!!
- 求助,修改数据出现System.NullReferenceException: 未将对象引用设置到对象的实例。
- 运行时出现如下错误是怎么回事?
- datagrid的问题
- 求救!显示后台数据,在线等待!等……
- aspx页面生成静态页后的问题?
- 如下代码运行时总是说insert into语法错误,为什么?错在这一行,count1=objcmd.executenonquery()
不过一开始control.Controls[i] is TextBox 的确为false
多循环几次就 ok了 运行完后 所有为 TextBox的值都清除了
foreach (Control control in Controls)
{
for (int i = 0; i < control.Controls.Count; i++)
{
if (control.Controls[i].GetType().Name.ToLower() == "textbox")
{
TextBox tb = (TextBox)control.Controls[i];
tb.Text = "";
}
}
} // 下面的方法也可以实现,但不提倡,因为try...catch...比较影响性能
foreach (Control control in Controls)
{
for (int i = 0; i < control.Controls.Count; i++)
{
try
{
TextBox tb = (TextBox)control.Controls[i];
tb.Text = "";
}
catch
{
continue;
}
}
}
{
if (c is TextBox) //为什么这里一直为false
{
TextBox tb = (TextBox)c;
tb.Text = "";
}
}
我记得这样就可以了
public void EmptyTextBoxs(Control Ctrl)
{
if (Ctrl is TextBox)
{
((TextBox)Ctrl).Text = ""; } foreach (Control childControl in Ctrl.Controls)
{
EmptyTextBoxs(childControl);
}
}
}
{
if (control is System.Windows.Forms.TextBox)
{
System.Windows.Forms.TextBox tb = (System.Windows.Forms.TextBox)control ;
tb.Text = String.Empty ;
}
{
if (control is System.Windows.Forms.TextBox)
{
System.Windows.Forms.TextBox tb = (System.Windows.Forms.TextBox)control ;
tb.Text = String.Empty ;
}
for(var i = 0 ; i < tb.length ; i ++)
{
if(tb[i].type == text)
{
tb[i].value = ''; }
}
你这个能确定都是textbox类型的控件吗?
{
foreach (Control childControl in c.Controls)
{
if (childControl is TextBox)
((TextBox)childControl).Text = "";
else
test(childControl);
}
}
test(this.Page)
public void EmptyTextBoxs(Control Ctrl)
{
if (Ctrl is TextBox)
{
((TextBox)Ctrl).Text = "";
} foreach (Control childControl in Ctrl.Controls)
{
EmptyTextBoxs(childControl);
}
}
}
把textbox看做html的input不就哦了!!