Home All Groups Group Topic Archive Search About
Author
16 Jun 2006 2:48 PM
Bob
Hi,

In aspx file, i have a table:
<asp:Table ID="table1" runat="server">
</asp:Table>

In the code-behind, i create rows and cells:
For i = 0 To 50
r = New TableRow()
for j = 0 To 20
c(i, j) = New TableCell()
r.Cells.Add(c(i, j))
Next
Table1.Rows.Add(r)
Next
....

With this, the table is rendered perfectly (data are displayed in all rows
and cells).

Now i added this line just after 'r.Cells.Add(c(i, j))':
Controls.Add(c(i, j))

Now i have no table anymore: data are dispayed the one after the other in
the page.

My questions are:
1) where is my table, why is is gone?
2) what's the difference between 'Controls.Add(c(i,j))' and
r.Cells.Add(c(i, j)) in this case?

Thanks for help
Bob

Author
16 Jun 2006 3:18 PM
Marina Levit [MVP]
In one case you are adding row and cell objects to a table. So it
appropriately renders them

In the other case you are adding them to the page - not to the table.  So
the page ends up with these objects, which it just renders in the order they
were added.  Unlike the table which actually knows how to deal with these,
the page just sort of throws them on one after the other.

It's the difference between adding an object to a Panel you have on your
page, or to the page itself. They are different containers for your objects.

Show quoteHide quote
"Bob" <s**@sdvsd.dc> wrote in message
news:OPisCQVkGHA.3848@TK2MSFTNGP04.phx.gbl...
> Hi,
>
> In aspx file, i have a table:
> <asp:Table ID="table1" runat="server">
> </asp:Table>
>
> In the code-behind, i create rows and cells:
> For i = 0 To 50
> r = New TableRow()
> for j = 0 To 20
> c(i, j) = New TableCell()
> r.Cells.Add(c(i, j))
> Next
> Table1.Rows.Add(r)
> Next
> ...
>
> With this, the table is rendered perfectly (data are displayed in all rows
> and cells).
>
> Now i added this line just after 'r.Cells.Add(c(i, j))':
> Controls.Add(c(i, j))
>
> Now i have no table anymore: data are dispayed the one after the other in
> the page.
>
> My questions are:
> 1) where is my table, why is is gone?
> 2) what's the difference between 'Controls.Add(c(i,j))' and
> r.Cells.Add(c(i, j)) in this case?
>
> Thanks for help
> Bob
>
>
Author
16 Jun 2006 3:37 PM
Bob
Thanks for your explanation.
I have just sent another problem, related with this, but first i had to know
this answer.


Show quoteHide quote
"Marina Levit [MVP]" <someone@nospam.com> wrote in message
news:%23EOxTgVkGHA.3536@TK2MSFTNGP05.phx.gbl...
> In one case you are adding row and cell objects to a table. So it
> appropriately renders them
>
> In the other case you are adding them to the page - not to the table.  So
> the page ends up with these objects, which it just renders in the order
they
> were added.  Unlike the table which actually knows how to deal with these,
> the page just sort of throws them on one after the other.
>
> It's the difference between adding an object to a Panel you have on your
> page, or to the page itself. They are different containers for your
objects.
>
> "Bob" <s**@sdvsd.dc> wrote in message
> news:OPisCQVkGHA.3848@TK2MSFTNGP04.phx.gbl...
> > Hi,
> >
> > In aspx file, i have a table:
> > <asp:Table ID="table1" runat="server">
> > </asp:Table>
> >
> > In the code-behind, i create rows and cells:
> > For i = 0 To 50
> > r = New TableRow()
> > for j = 0 To 20
> > c(i, j) = New TableCell()
> > r.Cells.Add(c(i, j))
> > Next
> > Table1.Rows.Add(r)
> > Next
> > ...
> >
> > With this, the table is rendered perfectly (data are displayed in all
rows
> > and cells).
> >
> > Now i added this line just after 'r.Cells.Add(c(i, j))':
> > Controls.Add(c(i, j))
> >
> > Now i have no table anymore: data are dispayed the one after the other
in
> > the page.
> >
> > My questions are:
> > 1) where is my table, why is is gone?
> > 2) what's the difference between 'Controls.Add(c(i,j))' and
> > r.Cells.Add(c(i, j)) in this case?
> >
> > Thanks for help
> > Bob
> >
> >
>
>