2013-01-17 48 views
0

有沒有辦法在後面的代碼中訪問「th」?我想添加填充到標題取決於項目值。在列表視圖中訪問「th」

<LayoutTemplate> 
     <table runat="server" > 
      <tr runat="server"> 
       <td runat="server"> 
        <table ID="itemPlaceholderContainer" runat="server" border="0" class="UserLayoutTbl"> 
         <tr runat="server" style=""> 
          <th runat="server" width="140" align="left"> 
           Date</th> 
          <th runat="server" width="140" align="left"> 
           Ref. No.</th> 
          <th runat="server" width="270" align="left"> 
           Description</th> 
          <%-- <th runat="server" width="90" align="right" style = '<%# GetAmountLabelStyle() %>'> 
           Amount</th>--%> 
           <th id="Th1" runat="server" width="90" align="right"> 
           Amount</th> 
         </tr> 
         <tr ID="itemPlaceholder" runat="server"> 
         </tr> 
        </table> 
       </td> 
      </tr> 

回答

1

首先給你想改變的元素給一個ID。在ListView的DataBind之後,您可以使用ListView的FindControl方法通過其ID來訪問該控件。然後,您可以將返回的控件轉換爲HtmlTableCell以正確處理它:

// thDate is the <th> ID 
HtmlTableCell thDate = lstItems.FindControl("thDate") as HtmlTableCell;