Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Getting dynamic controls/tables to render on page

Reply
Thread Tools

Getting dynamic controls/tables to render on page

 
 
jsever05@gmail.com
Guest
Posts: n/a
 
      08-01-2005
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!

 
Reply With Quote
 
 
 
 
sfarriss
Guest
Posts: n/a
 
      08-02-2005
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

"(E-Mail Removed)" 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!
>
>

 
Reply With Quote
 
 
 
 
JS
Guest
Posts: n/a
 
      08-03-2005
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...

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Easy Question ;-) How to render a html page in a table cell of an ASP.NET page SteveM ASP .Net 7 12-14-2006 08:10 PM
Accessing rails render method outside of view / Decorating render Glenn Gillen Ruby 0 11-17-2006 02:30 PM
Page.Render do not render complete page Lau Lei Cheong ASP .Net 1 05-15-2004 04:10 AM
Re: STRUTS: c:set alternative to render dynamic links Brock Heinz Java 0 07-30-2003 04:14 PM
Re: STRUTS: c:set alternative to render dynamic links Wendy S Java 0 07-30-2003 03:03 PM



Advertisments