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#,asp.net and .net framework2.
how to hide a td in a dynamically?

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

Helo

Hope this help

Using aspx page
<
table>

      <tr>

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

        </td>

      </tr>

    </table>

Using Dynemicaly

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

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

You need an attribute class:

 

 

 

 

 

 

 

 

 

 

 

[AttributeUsage(AttributeTargets.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);

}

HideTableIndefaultAttribute

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;

  //Menu1.DataBind();

 

  // Hiding tables

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

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

            DefaultIfEmpty(HideTableInDefaultAttribute.Default).First().Hide

           orderby t.DisplayName

           select t).ToList();

 

  Menu1.DataSource = tablesMain;

  Menu1.DataBind();

 

}

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)

[ScaffoldTable(false)]

public partial class Category

{

}

 

[HideTableInDefault(true)]

public partial class EmployeeTerritory

{

}

 

[HideTableInDefault(true)]

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
<table>
        <Tr>
             <td id= "tdsample" Runat="server">
                    your data here
              </td>
        </Tr>
</table>

CodeBehid

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">

<td>HELLO</td>

</tr>



Now in the event write this

this.tr1.Visible = false;

Regards
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
<table>
<tr>
<td id="tdcolumn" runat="server" style="display: none">
</td>
</tr>
</table>


  tdcolumn.Style.Add("Display","none");