Casting a LiteralControl to a Table

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
Pete2003Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
msdixonConnect With a Mentor Commented:
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
 
msdixonCommented:
by generating a string, instead of using an object, an option would be an HtmlTable control:
         HtmlTable tbl = new HtmlTable();
         tbl.InnerHtml = sHtml;
0
 
Pete2003Author Commented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
msdixonCommented:
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
 
msdixonCommented:
have you tried the Table control under the "Web Forms" tab?
0
 
Pete2003Author Commented:
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
 
msdixonCommented:
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
All Courses

From novice to tech pro — start learning today.