ボタンをクリックして、テーブル コントロールに行を追加したいと考えています。以下のコードを使用してみましたが、エラーが発生しました。誰か助けてもらえますか?
protected void btn_Click(object sender, EventArgs e)
{
//Table table = (Table)Page.FindControl("tblName");
TableRow tr = new TableRow();
tr.Cells.Add(new TableCell());
tr.Cells.Add(new TableCell());
tr.Cells.Add(new TableCell());
tr.Cells[0].Text = TextBox1.Text;
tr.Cells[1].Text = TextBox2.Text;
tr.Cells[2].Text = TextBox3.Text;
//add the row to the existing table.
this.tblName.Rows.Add(tr);
//this.tblName.Rows.Add();
}
------------------asp.net-------------------------
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="btn_Click" />
<table id="tblName" Runat="server" style="width:100%;">
<tr>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td>
<td>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></td>
</tr>
</table>
<br />
</div>
</form>