Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling an HTML table from code behind

I am trying to access an HTML table from code behind, and set its visible="false" property (depending on what value the user has selected). The table has an id value and a runat=server attribute.

How can I call the table from the code behind in C# 2008 and set its display?

like image 740
user279521 Avatar asked Apr 05 '10 13:04

user279521


People also ask

How can access HTML table in asp net code behind?

You have to add runat="server" tag to the HTML table and access that table by Id in Code behind. and then CAST it to HTMLTable.

How to create HTML Table in Code Behind in c#?

You will need to import the following namespaces. Inside the Page Load event, first a dynamic DataTable is created with some dummy data. Then using the StringBuilder class, an HTML String of HTML Table is built and is later assigned to the Literal control's Text property. DataTable dt = new DataTable();

How can add HTML code behind in asp net?

Take one local string variable TEMP. Create same html as you want to display on screen and store it in variable TEMP. You can take html creation of control in separate function based on requirement. Place that created html as innerHTML to your panel/div.


2 Answers

Make sure you have your table set up to run at server.

Example

<table id="tblMyTable" runat="server">
....
</table>

On server side you can access it by using the variable tblMyTable

To hide the visibility is not simple. There is not a property for it since it is a Html control rather than a server control.

I would wrap the table in an ASP.NET control such as a panel, and hide the panel.

like image 71
David Basarab Avatar answered Sep 20 '22 06:09

David Basarab


I would wrap the table in an <asp:Panel control and change the visible property on that instead.

like image 34
Joel Coehoorn Avatar answered Sep 18 '22 06:09

Joel Coehoorn