Solved

Casting a LiteralControl to a Table

Posted on 2004-08-25
7
571 Views
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...

Txs
Peter
0
Comment
Question by:Pete2003
  • 5
  • 2
7 Comments
 
LVL 9

Expert Comment

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

Author Comment

by:Pete2003
Comment Utility
Txs for the reply ...

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

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

Expert Comment

by:msdixon
Comment Utility
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).
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 9

Expert Comment

by:msdixon
Comment Utility
have you tried the Table control under the "Web Forms" tab?
0
 

Author Comment

by:Pete2003
Comment Utility
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 ...
0
 
LVL 9

Expert Comment

by:msdixon
Comment Utility
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.
0
 
LVL 9

Accepted Solution

by:
msdixon earned 400 total points
Comment Utility
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();
                              tr.Cells.Add(cell);
                        }
                        t.Rows.Add(tr);
                  }

                  Page.Controls.Add(t);

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now