2016-01-13 80 views
0

我有一張具有特定佈局的表格。它開始是這樣的:更改代碼中的HTML表格

<table> 
    <tr bgcolor="#007ACC" style="color:White"> 
     <td width="145"><asp:Label Text="" ID="lblLevel" runat="server" /></td><td width="80"></td><td width="30"></td><td width="145"><asp:Label Text="" ID="lblGroupNumber" runat="server" /></td><td width="60"></td><td width="10">Active</td> 
    </tr> 
    <tr> 
     <td colspan="5"> 
      <asp:TextBox ID="txtName" runat="server" width="460px"></asp:TextBox> 
     </td> 
     <td> 
      <asp:DropDownList ID="cboActive" runat="server" Width="50px"> 
       <asp:ListItem>Y</asp:ListItem> 
       <asp:ListItem>N</asp:ListItem> 
      </asp:DropDownList> 
     </td> 
    </tr> 

的問題是,在某些情況下,我需要它看起來像這樣:

<table> 
    <tr bgcolor="#007ACC" style="color:White"> 
     <td width="145"><asp:Label Text="" ID="lblLevel" runat="server" /></td><td width="80"></td><td width="30"></td><td width="145"><asp:Label Text="" ID="lblGroupNumber" runat="server" /></td><td width="60"></td><td width="10">Active</td> 
    </tr> 
    <tr> 
     <td colspan="2"> 
      <asp:TextBox ID="txtName" runat="server" width="460px"></asp:TextBox> 
     </td> 
     <td></td> 
     <td colspan="2"> 
      <asp:TextBox ID="txtNumber" runat="server" width="460px"></asp:TextBox> 
     </td> 
     <td> 
      <asp:DropDownList ID="cboActive" runat="server" Width="50px"> 
       <asp:ListItem>Y</asp:ListItem> 
       <asp:ListItem>N</asp:ListItem> 
      </asp:DropDownList> 
     </td> 
    </tr> 

我以前隱藏的文本框,那也沒問題。但我能想到的唯一辦法就是使用代碼隱藏td's。我已經看到了這一點:

How to hide columns in HTML table?

,但他們從來沒有解釋如何確定哪些td被隱藏。

所以,這可以在代碼中完成(最好在C#中的代碼隱藏)?如果是這樣,怎麼樣?

回答

2

在asp.net大多數元素可以作爲服務器控制來編程方式處理與runat組:

<td colspan="2" runat="server" id="tdToHide"> 
     <asp:TextBox ID="txtNumber" runat="server" width="460px"></asp:TextBox> 
</td> 

在C#:

tdToHide.Visible = false; 

這是很多很多方法來「隱藏的事情之一'在網頁上。

另一個是td上的條件CSS類。其顯示將通過頁面上的樣式進行處理。

+0

F'n brilliant,brotha!萬分感謝! –

+0

沒問題的隊友 –

0

您可以使用LiteralControl然後基於條件將內容或AddControl更改爲literalcontrol。這可以從後面的代碼執行