【问题标题】:Fetching control name inside html table in asp.net在asp.net的html表中获取控件名称
【发布时间】:2013-09-30 14:34:43
【问题描述】:

这是我的示例代码

for (int i = 0; i

System.Web.UI.Control ctr = SDTable1.Rows[i].Cells[0].Controls[i];

StudentDetailsChecklist.Items.Add(ctr.ID);

}

SDTable 是我的 Html 表,我想获取控件名称而不是 Id。

如果我使用上面的代码获取控件的 ID,我需要获取控件的名称。

谢谢 拉杰什库马尔

【问题讨论】:

  • 你可以使用 jquery 轻松完成
  • 请告诉我们你在哪里获得堆栈,而不是我们试图猜测。
  • 我只是在找码友。
  • @Rajeshkumar 有多种方法可以实现它,但这完全取决于您如何创建 html 表。请向我们展示如何创建 html 表的代码。
  • 它是一个带有静态控件的静态表格。我必须获取控件名称并将其传递给列表框。这是我的场景。

标签: html asp.net c#-4.0 .net-4.0


【解决方案1】:

归结为枚举控件层次结构中的所有控件:

IEnumerable<Control> EnumerateControlsRecursive(Control parent)
{
    foreach (Control child in parent.Controls)
    {
        yield return child;
        foreach (Control descendant in EnumerateControlsRecursive(child))
            yield return descendant;
    }
}

你可以这样使用它:

    foreach (Control c in EnumerateControlsRecursive(Page))
    {
        if(c is TextBox)
        {
            // do something useful
        }
    }

Source

【讨论】:

  • 我只想获取html表中的控件名称。
猜你喜欢
  • 1970-01-01
  • 2010-09-19
  • 2012-02-17
  • 1970-01-01
  • 2020-01-04
  • 2011-11-30
  • 2012-09-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多