[英]Accessing data from controls within a C# Table control?
As the title suggests, I'm having trouble accessing data in my Table control (System.Web.UI.WebControls.Table). 顾名思义,我无法访问Table控件(System.Web.UI.WebControls.Table)中的数据。 The layout is basically a dynamic web-based spreadsheet with TextBox controls in each TableCell. 布局基本上是一个基于Web的动态电子表格,每个TableCell中都有TextBox控件。 I was trying to do something like the code below, but I can't access the data. 我试图做类似下面的代码,但无法访问数据。 Any help would be appreciated. 任何帮助,将不胜感激。
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...
}
}
}
You can try to do it like: 您可以尝试这样做:
foreach (var control in this.Controls.OfType<TextBox>())
{
if (control.Text.Trim() != string.Empty)
{
//do your code..
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.