【问题标题】:Add <thead> tags to Table using System.Web.UI.WebControls使用 System.Web.UI.WebControls 将 <thead> 标记添加到 Table
【发布时间】:2014-07-30 12:23:26
【问题描述】:

我需要以某种方式将&lt;thead&gt; 标签添加到我的循环中。 tableHEaderRow 类只使用&lt;tr&gt;&lt;th&gt; 标签,我需要将它们嵌套在&lt;thead&gt; 标签中以进行样式设置。

我尝试过使用各种方法,包括字符串编写器和文字控件,但我似乎无法让它工作。

TableHeaderRow thr = new TableHeaderRow();
tbl.Controls.Add(new LiteralControl("<thead>")); // This is the line I need to add
foreach (DataColumn col in dt.Columns)
{
  TableHeaderCell th = new TableHeaderCell();
  th.Text = col.Caption;
  thr.Controls.Add(th);
}
tbl.Controls.Add(new LiteralControl("</thead>")); // This is the line I need to add
tbl.Controls.Add(thr);
...
...
tbl.RenderControl(w);
tableString = sw.ToString();

// Then my aspx page displays my tableString variable.

还有什么其他方法可以尝试手动将&lt;thead&gt; 标签添加到我的循环中? 我正在使用 System.Web.UI.WebControls。

【问题讨论】:

  • 当我尝试使用 literalControl 我得到Table' cannot have children of type 'LiteralControl
  • 已经被问过很多次了,甚至在 SO 上也是如此(开始查看this search
  • 我还没有看到答案@AndreasNiedermair 是 c# 代码。我不是在寻找 aspx 代码。
  • @Frantumn 有什么你不能用 C# 做的吗?这就是这样做的方法,这就是答案,即使......它还没有准备好使用代码。

标签: c#


【解决方案1】:

您将 TableRow 控件设置为位于具有TableSelection 属性的&lt;thead&gt; 中。

例如:&lt;asp:TableRow TableSection="TableHeader"/&gt; 将在表格的&lt;thead&gt; 部分生成一个 TableRow 控件。

也可以动态设置rowControl.TableSection = TableRowSection.TableHeader;

三个选项分别是TableHeader、TableBody和TableFooter。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-25
    • 1970-01-01
    • 2014-10-07
    • 1970-01-01
    相关资源
    最近更新 更多