如何使用C#代码更改ASP.NET表中单元格的值

use*_*941 2 c# asp.net

我希望能够使用后面的代码来设置表格中单元格的值

<asp:Table ID="Table1" runat="server" CellPadding="10"
GridLines="Both" HorizontalAlign="Center" BackColor="Cornsilk">
<asp:TableRow ID="Row1">
<asp:TableCell ID="Cell1"></asp:TableCell>
Run Code Online (Sandbox Code Playgroud)

这可能吗?

Tim*_*ter 5

成功runat=server:

<asp:TableCell runat="server" ID="Cell1"></asp:TableCell>
Run Code Online (Sandbox Code Playgroud)

你可以直接从codebehind访问它:

Cell1.Text = "New Value"; 
Run Code Online (Sandbox Code Playgroud)

否则你可以通过Rows和Cells表访问它:

Table1.Rows[0].Cells[0].Text = "New Value";
Run Code Online (Sandbox Code Playgroud)