ASP.NET - how to hide a td in a table in C# - Asked By George n t on 17-Nov-11 04:14 AM

Hi friends,

I am using C#, and .net framework2.
how to hide a td in a dynamically?

thanks in advance
Chintan Vaghela replied to George n t on 17-Nov-11 04:20 AM


Hope this help

Using aspx page


        <td id="tdTemp" runat="server" style="display: none">




Using Dynemicaly

tdTemp.Style.Add(HtmlTextWriterStyle.Display, "none");

Lalit M replied to George n t on 17-Nov-11 04:20 AM

You need an attribute class:













public class HideTableInDefaultAttribute : Attribute


  public Boolean Hide { get; private set; }


  public HideTableInDefaultAttribute(Boolean hide)


    Hide = hide;

  }  // this will allow us to have a default set to false

  public static HideTableInDefaultAttribute Default =

    new HideTableInDefaultAttribute(false);



And now the code in the Default.aspx:










protected void Page_Load(object sender, EventArgs e)


  System.Collections.IList visibleTables = Global.DefaultModel.VisibleTables;

  if (visibleTables.Count == 0)

    throw new InvalidOperationException(

      @"There are no accessible tables.

      Make sure that at least one data model is

      registered in Global.asax and scaffolding is

      enabled or implement custom pages.");


  //Menu1.DataSource = visibleTables;



  // Hiding tables

  var tablesMain = (from t in Global.DefaultModel.VisibleTables

           where !t.Attributes.OfType<HideTableInDefaultAttribute>().


           orderby t.DisplayName

           select t).ToList();


  Menu1.DataSource = tablesMain;




Default.aspx Page_Load event handler

Note in the where clause the DefaultIfEmpty which allows you to specify the default value to return if no value found. This means that you will always get a value and the default value will have the Hide property set to false because of the Default keyword in the Attribute definition.

Now some sample metadata:

// note the differance in the result of using

// ScaffoldTable(false) over HideTableInDefault(true)


public partial class Category





public partial class EmployeeTerritory





public partial class Product



Suchit shah replied to George n t on 17-Nov-11 04:21 AM
Do it like below on aspx page

ASPX page
             <td id= "tdsample" Runat="server">
                    your data here


tdsample.visible = false;

In this way u can hide whole TD

hope u get it
Riley K replied to George n t on 17-Nov-11 04:38 AM

Use the Runat="Server " so that you can get the ID and use Visible property

<tr id="tr1" runat="server">



Now in the event write this

this.tr1.Visible = false;

kalpana aparnathi replied to George n t on 17-Nov-11 05:40 AM
Try this javascript function

if(navigator.appName.indexOf("Microsoft") > -1){
var canSee = 'block'
} else {
var canSee = 'table-row';
Sunil Darji replied to George n t on 17-Nov-11 08:48 AM
<td id="tdcolumn" runat="server" style="display: none">