将生成的行和列添加到 aspx 文件中的表中
我想将我的表格添加到页面中,并将表格控件放入 aspx 文件中,并在 aspx.cs 文件中生成列和行:
if (Page.IsValid)
{
var start = Int32.Parse(TextBox1.Text);
var slut = Int32.Parse(TextBox2.Text);
var diff = Int32.Parse(TextBox3.Text);
for(int i = 0; i < (slut - start) / diff; i++)
{
TableRow tr = new TableRow();
tr.ID = "row" + i.ToString();
for (int j = 0; j <= 2; j++)
{
TableCell tc = new TableCell();
tc.ID = "cell" + j.ToString();
tr.Cells.Add(tc);
}
??.Rows.Add(tr);
}
}
在 aspx 中:
<asp:Table ID="Table" runat="server" Visible="true">
</asp:Table>
我应该在“??”的位置写什么是?身份证不行啊
I want to add my table to the page, and the Table control is put in the aspx file and the columns and rows is generated in the aspx.cs file:
if (Page.IsValid)
{
var start = Int32.Parse(TextBox1.Text);
var slut = Int32.Parse(TextBox2.Text);
var diff = Int32.Parse(TextBox3.Text);
for(int i = 0; i < (slut - start) / diff; i++)
{
TableRow tr = new TableRow();
tr.ID = "row" + i.ToString();
for (int j = 0; j <= 2; j++)
{
TableCell tc = new TableCell();
tc.ID = "cell" + j.ToString();
tr.Cells.Add(tc);
}
??.Rows.Add(tr);
}
}
And in aspx:
<asp:Table ID="Table" runat="server" Visible="true">
</asp:Table>
What should I write where the "??" is? ID doesn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将您的 ID 更改为 Table1 或其他内容。
Table
是一个类的名称,这可能就是您遇到问题的原因。change your ID to Table1 or something else.
Table
is the name of a class which is probably why you are having a problem.首先将表的 ID 更改为:
然后:
我认为 ASP.NET 变得很混乱,因为它有一个名为
Table
的控件,并且您尝试使用ID="Table 来标识您的表“
。First change the ID of your table to:
Then:
I think ASP.NET is getting confused because it has a control with the name
Table
and you tried to identify your table withID="Table"
.