2

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Filip Nilsson
  • 407
  • 7
  • 20
  • you should not really ask that question. you have the ID of a table and that's the object where you want to add rows – Sebastian Siek Feb 22 '12 at 16:09
  • 1
    @SebastianSiek the OP had made a mistake of creating the ID the same as the class name and didn't understand that, thus the question – peroija Feb 22 '12 at 16:13

2 Answers2

2

change your ID to Table1 or something else. Table is the name of a class which is probably why you are having a problem.

peroija
  • 1,982
  • 4
  • 21
  • 37
1

First change the ID of your table to:

<asp:Table ID="MyTable" runat="server" Visible="true">

Then:

MyTable.Rows.Add(tr);

I think ASP.NET is getting confused because it has a control with the name Table and you tried to identify your table with ID="Table".

Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480