感觉代码不是一般的傻。如果有一百个不知道怎么搞了。在线等我知道foreach(Control c in TextBox)这种方法。但是用在这里有点不知所措。=====================================================            if ((State3 % 10) == 0)
            {
                textBox7.Text = HttpUtility.UrlDecode(dt3.Rows[0][3].ToString(), Encoding.Default);
            }
            if ((State3 % 10) == 1)
            {
                textBox8.Text = HttpUtility.UrlDecode(dt3.Rows[0][3].ToString(), Encoding.Default);
            }
            if ((State3 % 10) == 2)
            {
                textBox9.Text = HttpUtility.UrlDecode(dt3.Rows[0][3].ToString(), Encoding.Default);
            }
            if ((State3 % 10) == 3)
            {
                textBox10.Text = HttpUtility.UrlDecode(dt3.Rows[0][3].ToString(), Encoding.Default);
            }
            if ((State3 % 10) == 4)
            {
                textBox11.Text = HttpUtility.UrlDecode(dt3.Rows[0][3].ToString(), Encoding.Default);
            }
            if ((State3 % 10) == 5)
            {
                textBox12.Text = HttpUtility.UrlDecode(dt3.Rows[0][3].ToString(), Encoding.Default);
            }
            if ((State3 % 10) == 6)
            {
                textBox13.Text = HttpUtility.UrlDecode(dt3.Rows[0][3].ToString(), Encoding.Default);
            }
            if ((State3 % 10) == 7)
            {
                textBox14.Text = HttpUtility.UrlDecode(dt3.Rows[0][3].ToString(), Encoding.Default);
            }
            if ((State3 % 10) == 8)
            {
                textBox15.Text = HttpUtility.UrlDecode(dt3.Rows[0][3].ToString(), Encoding.Default);
            }
            if ((State3 % 10) == 9)
            {
                textBox16.Text = HttpUtility.UrlDecode(dt3.Rows[0][3].ToString(), Encoding.Default);
            }            Uri u = new Uri(textBox7.Text.TrimEnd());
            webBrowser1.Navigate(u);            Uri u1 = new Uri(textBox8.Text.TrimEnd());
            webBrowser2.Navigate(u1);            Uri u10 = new Uri(textBox9.Text.TrimEnd());
            webBrowser10.Navigate(u10);            Uri u3 = new Uri(textBox10.Text.TrimEnd());
            webBrowser3.Navigate(u3);            Uri u4 = new Uri(textBox11.Text.TrimEnd());
            webBrowser4.Navigate(u4);            Uri u5 = new Uri(textBox12.Text.TrimEnd());
            webBrowser5.Navigate(u5);            Uri u6 = new Uri(textBox13.Text.TrimEnd());
            webBrowser6.Navigate(u6);            Uri u7 = new Uri(textBox14.Text.TrimEnd());
            webBrowser7.Navigate(u7);            Uri u8 = new Uri(textBox15.Text.TrimEnd());
            webBrowser8.Navigate(u8);            Uri u9 = new Uri(textBox16.Text.TrimEnd());
            webBrowser9.Navigate(u9);

解决方案 »

  1.   

    int a = State3 % 10;
    if (a >=0 and a<=9)
    {
    "textBox"+(7+a ).Text = HttpUtility.UrlDecode(dt3.Rows[0][3].ToString(), Encoding.Default); 
    )哈哈,关注中,"textBox"+(7+a )怎么把这个字符串弄成对象,装箱操作吧?
      

  2.   

    用索引器设置n个TextBox,
    再用for赋值!!
      

  3.   

    "textBox"+(7+a ).Text = HttpUtility.UrlDecode(dt3.Rows[0][3].ToString(), Encoding.Default); 
    int _TextBoxIndex =7+(State3 % 10);
    this.Controls["textBox"+_TextBoxIndex.ToString()].Text=HttpUtility.UrlDecode(dt3.Rows[0][3].ToString(), Encoding.Default); 
    ...你把名字整理的有点规律..或者设置标签索引什么的.
      

  4.   

                //任何东西都需要一个规则,比如控件的坐标值,除非你能找到一个规则可以让程序自己算出来,否则你就只能自己定义,即使是100个也没办法。
                int state = State3 % 10;
                string Urlstring = dt3.Rows[0][3].ToString(),;            //先定义十个文本控件和浏览器控件
                TextBox[] tbs = new TextBox[10];
                WebBrowser[] wbs = new WebBrowser[tbs.Length];            //遍历控件
                for (int index = 0; index < tbs.Length; index++)
                {
                    //文本控件
                    tbs[index] = new TextBox();
                    TextBox tb = tbs[index];
                    tb.Name = "textBox" + index.ToString();                tb.Width = 200;
                    tb.Height = 20;
                    
                    
                    if (index == state)
                    {
                        //满足条件的TextBox值
                        tb.Text = System.Web.HttpUtility.UrlDecode(Urlstring, System.Text.Encoding.Default); 
                    }                tb.Top = 25 * index + 5;
                    tb.Left = 5;
                                    //浏览器控件
                    wbs[index] = new WebBrowser();
                    WebBrowser wb = wbs[index];
                    wb.Name = "webBrowser" + index.ToString();
                    
                    wb.Width = 500;
                    wb.Height = 100;                wb.Left = 5;
                    wb.Top = 105 * index + 260;                //添加链接
                    if (string.IsNullOrEmpty(tb.Text)) continue;                Uri url = new Uri(tb.Text.TrimEnd());
                    wb.Navigate(url);            }            //添加到窗体
                this.Controls.AddRange(tbs);
                this.Controls.AddRange(wbs);
      

  5.   

    谢谢zjmotion 耐心教导
      

  6.   

    textBox 的ID和==后面的数字设置成一致不就OK了?
      

  7.   

    foreach (Control txtobj in this.Page.Controls){ 
        if (txtobj.GetType().Name == "TextBox") 
        { 
           // ((TextBox)txtobj).Text = "";//这是第一种方法赋值,第二种在下面 
            TextBox tb = new TextBox(); 
             tb = (TextBox)this.FindControl(txtobj.ID); nbsp;          tb.Text = ""; 
        } 
    }
      

  8.   

    看看这个也行
    http://topic.csdn.net/t/20040831/15/3326430.html