【问题标题】:Adding textfield to tablecells in the backend C#将文本字段添加到后端 C# 中的表格单元格
【发布时间】:2018-11-21 13:14:01
【问题描述】:

单击按钮后,我将表格行(包含 5 个表格单元格)添加到表格中。下面的代码工作正常,但我正在努力使这些表格单元格成为文本字段。因此,我应该以某种方式将以下内容放入表格单元格中:

<input type="text" id="rol_totaal" runat="server" class="tbl_input"/>

有什么想法可以在以下函数中实现吗?我在 ASP.NET 中使用 C#。

public void BtnAddCost_Click(object sender, EventArgs e)
{


    var row = new HtmlTableRow() {  };
    var cell1 = new HtmlTableCell() { Height = "25px", InnerText="extra cost" };
    cell1.Attributes.Add("class", "title_kost_tbl tbl_border_bottom");
    var cell2 = new HtmlTableCell() { InnerText = "test 2" };
    cell1.Attributes.Add("class", "grey_bg");
    var cell3 = new HtmlTableCell() { InnerText = "test 3" };
    cell1.Attributes.Add("class", "grey_bg");
    var cell4 = new HtmlTableCell() { InnerText = "test 4" };
    cell1.Attributes.Add("class", "grey_bg");
    var cell5 = new HtmlTableCell() { InnerText = "test 5" };
    cell1.Attributes.Add("class", "grey_bg");
    row.Cells.Add(cell1);
    row.Cells.Add(cell2);
    row.Cells.Add(cell3);
    row.Cells.Add(cell4);
    row.Cells.Add(cell5);
    cost_tbl.Rows.Add(row);

}

【问题讨论】:

    标签: c# asp.net html-table textfield


    【解决方案1】:

    认为你应该能够做这样的事情,但是我没有机会测试它,因为我远离我的电脑:

    public void BtnAddCost_Click(object sender, EventArgs e)
    {
        var row = new HtmlTableRow() {  };
        var cell1 = new HtmlTableCell() { Height = "25px", InnerText="extra cost" };
        cell1.Attributes.Add("class", "title_kost_tbl tbl_border_bottom");
        var cell2 = new HtmlTableCell() { InnerHtml = "<input type=\"text\" id=\"rol_totaal1\" runat=\"server\" class=\"tbl_input\"/>" };
        cell1.Attributes.Add("class", "grey_bg");
        var cell3 = new HtmlTableCell() { InnerHtml = "<input type=\"text\" id=\"rol_totaal2\" runat=\"server\" class=\"tbl_input\"/>" };
        cell1.Attributes.Add("class", "grey_bg");
        var cell4 = new HtmlTableCell() { InnerHtml = "<input type=\"text\" id=\"rol_totaal3\" runat=\"server\" class=\"tbl_input\"/>" };
        cell1.Attributes.Add("class", "grey_bg");
        var cell5 = new HtmlTableCell() { InnerHtml = "<input type=\"text\" id=\"rol_totaal4\" runat=\"server\" class=\"tbl_input\"/>" };
        cell1.Attributes.Add("class", "grey_bg");
        row.Cells.Add(cell1);
        row.Cells.Add(cell2);
        row.Cells.Add(cell3);
        row.Cells.Add(cell4);
        row.Cells.Add(cell5);
        cost_tbl.Rows.Add(row);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多