Casting a LiteralControl to a Table

Posted on 2004-08-25
Last Modified: 2012-06-27
Hi All,

I have created a normal HTML table on the fly and I have added it to a panel using Add(new LiteralControl(sHTML))

The thing is now I want to process the data in the table, therefore I would like to somehow cast the literal control to a table.

I have tried doing a cast but it does not work.
I have tried creating a table using Table, tableRow, TableCell but once the table is added, it reads out as a LiteralCOntrol again.

I would like to avoid having to erite a parser for the text of the literal control and just be able to put the data into a table structure whcih would be then accessible through my C# code...

Question by:Pete2003
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2

Expert Comment

ID: 11893230
by generating a string, instead of using an object, an option would be an HtmlTable control:
         HtmlTable tbl = new HtmlTable();
         tbl.InnerHtml = sHtml;

Author Comment

ID: 11893341
Txs for the reply ...

That was one of the 1st things I tried ...

It generates an error:
'HtmlTable' does not support the InnerHtml property.

Expert Comment

ID: 11898541
well, it doesn't look good. you'll have to either change your code to generate an HtmlTable control, or parse the sHTML variable and build the control that way. i would go with the first (changing your code to generate an HtmlTable object instead of a string).
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Expert Comment

ID: 11898549
have you tried the Table control under the "Web Forms" tab?

Author Comment

ID: 11899968
The thing is that if you generate the table using the Table control or by yourself, once it's on the page it still is a LiteralControl so that wan't help ...

Expert Comment

ID: 11908546
an HmlTable control maybe, but if you enable viewstate (default), the web control table should work... i'll give it a try in a minute.

Accepted Solution

msdixon earned 400 total points
ID: 11908621
this worked:

                  string id = "testTable";
                  Table t = new Table();
                  t.ID = id;
                  for (int i = 0; i < 5; i++)
                        TableRow tr = new TableRow();
                        for (int j = 0; j < 10; j++)
                              TableCell cell = new TableCell();
                              cell.Text  = i.ToString() + ": " + j.ToString();


                  ((Table) Page.FindControl(id)).Rows[0].Cells[0].Text += "Test";

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor ( Top Charts is a view in which you can set seve…
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question