我在点击按钮后将表格行(包含5个表格单元格)添加到表格中。下面的代码工作正常,但我正在努力使这些tablecells文本字段。所以我不知何故应该在表格中放入以下内容:
<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);
}
答案 0 :(得分:0)
认为你应该可以做这样的事情,但是我没有机会测试它,因为我离开了我的电脑:
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);
}