Getting dynamic controls/tables to render on page

Discussion in 'ASP .Net Web Controls' started by jsever05@gmail.com, Aug 1, 2005.

  1. Guest

    I have looked around the web for a solution to this, but I can't find
    it. It's probably something simple I have overlooked.

    I am trying to build a dynamic table on the server-side and render its
    contents to the .aspx page. I placed the following code on the .aspx
    page:


    <asp:Table id="TestTable" runat="server"></asp:Table>


    Then in my page class, I added the following member variable:


    System.Web.UI.HtmlControls.HtmlTable TestTable;


    Finally, in the Page_Init() function I added the following code:


    TestTable = new HtmlTable();

    HtmlTableRow theRow = new HtmlTableRow();

    TestTable.Rows.Add(theRow);

    HtmlTableCell theCell = new HtmlTableCell();

    theRow.Cells.Add(theCell);

    HyperLink theLink = new HyperLink();

    theCell.Controls.Add(theLink);

    theLink.Target = "StatusOrders.aspx";
    theLink.ID ="link1";
    theLink.Text = "Test Text aaaaa";


    When I run the code, the only thing that renders as HTML is:

    <table id="TestTable" border="0"></table>

    I get nothing for the row, cell, or link that I added. I tried putting
    this code in the Page_Load() event, the Page_Init() event, and a
    constructor function that I created for the page object, and it doesn't
    change. Can someone help me to render this properly?

    Thanks!
    , Aug 1, 2005
    #1
    1. Advertising

  2. sfarriss Guest

    Is there a reason you have this line -> TestTable = new HtmlTable();

    You have already declared it as new by <asp:Table id="TestTable"
    runat="server"></asp:Table> on the page itself.

    If you want a dynamic table just use:
    HtmlTable ht = new HtmlTable();
    this.controls.add(ht);

    Also, if you leave it on the page you will want to declare it as
    protected System.Web.UI.HtmlControls.HtmlTable TestTable;

    HTH

    "" wrote:

    > I have looked around the web for a solution to this, but I can't find
    > it. It's probably something simple I have overlooked.
    >
    > I am trying to build a dynamic table on the server-side and render its
    > contents to the .aspx page. I placed the following code on the .aspx
    > page:
    >
    >
    > <asp:Table id="TestTable" runat="server"></asp:Table>
    >
    >
    > Then in my page class, I added the following member variable:
    >
    >
    > System.Web.UI.HtmlControls.HtmlTable TestTable;
    >
    >
    > Finally, in the Page_Init() function I added the following code:
    >
    >
    > TestTable = new HtmlTable();
    >
    > HtmlTableRow theRow = new HtmlTableRow();
    >
    > TestTable.Rows.Add(theRow);
    >
    > HtmlTableCell theCell = new HtmlTableCell();
    >
    > theRow.Cells.Add(theCell);
    >
    > HyperLink theLink = new HyperLink();
    >
    > theCell.Controls.Add(theLink);
    >
    > theLink.Target = "StatusOrders.aspx";
    > theLink.ID ="link1";
    > theLink.Text = "Test Text aaaaa";
    >
    >
    > When I run the code, the only thing that renders as HTML is:
    >
    > <table id="TestTable" border="0"></table>
    >
    > I get nothing for the row, cell, or link that I added. I tried putting
    > this code in the Page_Load() event, the Page_Init() event, and a
    > constructor function that I created for the page object, and it doesn't
    > change. Can someone help me to render this properly?
    >
    > Thanks!
    >
    >
    sfarriss, Aug 2, 2005
    #2
    1. Advertising

  3. JS Guest

    The main reason I added the new HtmlTable() line is because if I didn't
    it gives me a run time error saying the object did not exist. However,
    I just tried it again by converting everything from HtmlTable, HtmlRow,
    etc. to just Table, Row, Cell, etc. and I didn't get that error.

    However, I still can't get the dynamic rows, cells, and cell contents
    to actually render as HTML. Maybe I am asking the wrong question. Here
    is the right question:

    Can someone give me a simple step-by-step example of how to create a
    dynamic table with a variable number of rows, cells, etc., position it
    on the page where I want it, and have it render and display? It should
    only take a few steps, I believe...
    JS, Aug 3, 2005
    #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. Lau Lei Cheong

    Page.Render do not render complete page

    Lau Lei Cheong, May 15, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,049
    Lau Lei Cheong
    May 15, 2004
  2. Ronald
    Replies:
    2
    Views:
    822
    Robbe Morris [C# MVP]
    Jan 17, 2006
  3. Denny Smolinski via .NET 247

    Dynamic Controls, Placeholder, Retrieve Information from Dynamic Controls

    Denny Smolinski via .NET 247, May 4, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    453
    Eidolon
    May 4, 2004
  4. Glenn Gillen
    Replies:
    0
    Views:
    265
    Glenn Gillen
    Nov 17, 2006
Loading...

Share This Page