0

正如标题所示,我在访问表格控件 (System.Web.UI.WebControls.Table) 中的数据时遇到问题。布局基本上是一个基于 Web 的动态电子表格,每个 TableCell 中都有 TextBox 控件。我试图做类似下面代码的事情,但我无法访问数据。任何帮助,将不胜感激。

        foreach (Control c in this.Controls)
        {
            if (c.GetType().ToString() == "System.Windows.Form.Textbox")
            { 
                TextBox t = c as TextBox;
                if (t.Text.Trim() != "")
                {
                    // Do more things based on t.ID...
                }
             }
         }
4

1 回答 1

0

您可以尝试这样做:

        foreach (var control in this.Controls.OfType<TextBox>())
        {
            if (control.Text.Trim() != string.Empty)
            {
                //do your code..
            }
        }
于 2012-05-08T14:40:49.903 回答