如何在 Web 控件(例如 C# 中的 TableCell)中包含 html 元素
How to include html elements inside a webcontrol such as a TableCell in C#
我正在网络表单中编写代码,以便在单击按钮后向 table 添加行。在一些单元格中,我需要添加 html 元素,例如文本框和下拉菜单,
protected void LinkButton1_Click(object sender, EventArgs e)
{
TableRow row = new TableRow();
TableCell cell1 = new TableCell();
cell1.Text = "<input type=\"text\"></input>";
row.Cells.Add(cell1);
//proptable is the table id
PropTable.Rows.Add(row);
}
如果我这样写就可以了。
但是有没有更准确的方法来做到这一点?
感谢您的帮助。
您可以像这样轻松地向 TextBox 添加控件:
protected void LinkButton1_Click(object sender, EventArgs e)
{
TableRow row = new TableRow();
TableCell cell1 = new TableCell();
TextBox textbox = new TextBox();
textbox.Text = "Testing...";
//cell1.Text = "<input type=\"text\"></input>";
cell1.Controls.Add(textbox);
row.Cells.Add(cell1);
//proptable is the table id
PropTable.Rows.Add(row);
}
我正在网络表单中编写代码,以便在单击按钮后向 table 添加行。在一些单元格中,我需要添加 html 元素,例如文本框和下拉菜单,
protected void LinkButton1_Click(object sender, EventArgs e)
{
TableRow row = new TableRow();
TableCell cell1 = new TableCell();
cell1.Text = "<input type=\"text\"></input>";
row.Cells.Add(cell1);
//proptable is the table id
PropTable.Rows.Add(row);
}
如果我这样写就可以了。 但是有没有更准确的方法来做到这一点? 感谢您的帮助。
您可以像这样轻松地向 TextBox 添加控件:
protected void LinkButton1_Click(object sender, EventArgs e)
{
TableRow row = new TableRow();
TableCell cell1 = new TableCell();
TextBox textbox = new TextBox();
textbox.Text = "Testing...";
//cell1.Text = "<input type=\"text\"></input>";
cell1.Controls.Add(textbox);
row.Cells.Add(cell1);
//proptable is the table id
PropTable.Rows.Add(row);
}