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?
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.
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();
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.
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.
I would wrap the table in an <asp:Panel
control and change the visible property on that instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With