2013-01-17 50 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;