questions about Controls.add

Discussion in 'ASP .Net Web Controls' started by Bob, Jun 16, 2006.

  1. Bob

    Bob Guest

    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
     
    Bob, Jun 16, 2006
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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
    >
    >
     
    Marina Levit [MVP], Jun 16, 2006
    #2
    1. Advertising

  3. Bob

    Bob Guest

    Thanks for your explanation.
    I have just sent another problem, related with this, but first i had to know
    this answer.


    "Marina Levit [MVP]" <> wrote in message
    news:%...
    > 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" <> wrote in message
    > news:...
    > > 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
    > >
    > >

    >
    >
     
    Bob, Jun 16, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    4
    Views:
    7,232
    Steven Cheng[MSFT]
    Nov 9, 2005
  2. Bob

    questions about Controls.add

    Bob, Jun 16, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    322
  3. Nathan Sokalski
    Replies:
    5
    Views:
    1,082
    Gaurav Vaish \(www.Edujini-Labs.com\)
    Jan 10, 2007
  4. Chad Scharf
    Replies:
    3
    Views:
    947
    Chad Scharf
    Oct 18, 2007
  5. Vijay
    Replies:
    2
    Views:
    664
    Öö Tiib
    May 7, 2010
Loading...

Share This Page