Chinaunix首页 | 论坛 | 博客
  • 博客访问: 80428
  • 博文数量: 64
  • 博客积分: 1545
  • 博客等级: 上尉
  • 技术积分: 392
  • 用 户 组: 普通用户
  • 注册时间: 2012-10-23 15:23
文章分类

全部博文(64)

文章存档

2013年(1)

2012年(63)

我的朋友

分类: 嵌入式

2012-12-13 21:57:23

winform窗体遍历窗体上的TextBox病赋空值、

一、方法一

foreach (Control c in this.Controls)
{
    if (c is TextBox)
    {
        TextBox tb = (TextBox)c;
        tb.Text = string.Empty;
    }
}

二、方法二
foreach (Control col in this.Controls)
{
    if (col.GetType().Name.Equals("TextBox"))
    {
        ((TextBox)col).Text = string.Empty;
    }
}

asp.net 程序遍历TextBox,并赋String.Empty

一、方法一

foreach (Control ctl in form1.Controls)//这儿使用的是表达的名称
{
    if (ctl.GetType().Name == "TextBox")
    {
        TextBox tb = new TextBox();
        tb = (TextBox)this.form1.FindControl(ctl.ID);
        tb.Text = string.Empty;
    }
}

二、方法二

foreach (Control ctrl in this.Page.Controls)//第一层编号,找到htmlHead/headform
{
    foreach (Control ctl in ctrl.Controls)//第二层编号可以找到Form中的TextBox
    {
        string temp = ctl.GetType().ToString();
        if (ctl.GetType() == typeof(TextBox))
        {
            TextBox tb = (TextBox)ctl;
            tb.Text = "";
        }
    }
}

三 、递归遍历窗体上的TextBox并赋值

void FindTextBox(Control ctl)
{
    foreach (Control parent in ctl.Controls)
    {
        foreach (Control c in parent.Controls)
        {
            if (c.GetType().ToString() == "System.Web.UI.WebControls.TextBox")
                ((TextBox)c).Text = "Coool";
            FindTextBox(parent);
        }          
    }
}          

四 、Javascript遍历窗体上的所有TextBox并置空值



http://1906754.blog.51cto.com/1896754/660117

阅读(390) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~