HTML-ize a server-side control

J

John

Hi all,

Perhaps I've drawn a blank here but is there any way for me to use the
server-side objects (perhaps the HTMLTable in conjunction with
HTMLTableCell) to create a table with multiple rows and cells and then dump
the HTMLTable object into my source?

I use these controls when I need to gain access to cells and such upon
postbacks but was wondering about doing this the other way around as opposed
to building a long string using the StringBuilder.Append method.

Perhaps build the whole table object and somehow dump it into a literal
control?

Thanks in advance for any help forthcoming...

Regards
John.
 
M

Marius Tennes Krogh

I'm not shure wether this is what you want to achieve. Anyway,
You can use the RenderControl method of the control (here Table control);
Example:

Let's say your Table-control is called tblData

Table tblData = new Table();
//Now fill your table with your data
//...
//..

System.IO.StringWriter sWriter = new System.IO.StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(sWriter);
tblData.RenderControl(htmlWriter);
string htmlCodeForTable = sWriter.ToString();



Marius
 
A

addup

I know you've figured it out, but another option is to add your newly
created HTML Table as a child of an existing control

example: page.controls.add

This has additional benefits over the simple render html that I'll
leave you to discover :)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top