2017-08-30 106 views
1

我正在使用引導程序來摺疊並展開表,這是工作正常,但我使用類而不是ID。這樣,擴展一行就可以擴展所有的行,而不僅僅是那一行。我的問題是我的數據目標如何指向嵌套的中繼器ID? transactionCollapse ID無法直接定位,我試過做<%=transactionGroupedList.FindControl("transactionCollapse")%>,但它拋出了一個錯誤。ASP嵌套中繼器ID

<tbody> 
    <asp:Repeater runat="server" ID="transactionGroupedList" OnItemDataBound="TransactionGroupedDataList_ItemDataBound"> 
     <ItemTemplate> 
      <tr> 
       <!-- This line should target the transactionCollapse ID below instead of the class --> 
       <td data-toggle="collapse" data-target=".transactionCollapse"> 
        <span id="transactionGroupCollapseIcon" runat="server" class="fonticon-down-arrow"></span> 
        <custom:Label runat="server" ID="transactionActivityDataColumnLabel"></custom:Label>&nbsp; 
       </td> 
       <td> 
        <custom:Label runat="server" ID="transactionDateDataColumnLabel"> 
        </custom:Label> 
       </td> 
       <td> 
        <custom:Label runat="server" ID="transactionNumberDataColumnLabel"> 
        </custom:Label> 
       </td> 
       <td> 
        <custom:Label runat="server" ID="transactionAmountDataColumnLabel"> 
        </custom:Label> 
       </td> 
       <td> 
        <custom:Label runat="server" ID="transactionStatusDataColumnLabel"> 
        </custom:Label> 
       </td> 
      </tr> 
      <asp:Repeater runat="server" ID="transactionDetailList" OnItemDataBound="TransactionDetailsDataList_ItemDataBound"> 
       <ItemTemplate> 
        <tr id="transactionCollapse" runat="server" class="collapse transactionCollapse"> 
         <td colspan="2"> 
          <custom:Label runat="server" ID="transactionDetail"> 
          </custom:Label> 
         </td> 
         <td> 
          <custom:Label runat="server" ID="transactionDetailTransactionNumber"> 
          </custom:Label> 
         </td> 
         <td> 
          <custom:Label runat="server" ID="transactionDetailAmount"> 
          </custom:Label> 
         </td> 
        </tr> 
       </ItemTemplate> 
      </asp:Repeater> 
     </ItemTemplate> 
    </asp:Repeater> 
</tbody> 

Online Payment行就是摺疊/展開下面的Posting -MP Payment行。此用戶只有一個Online Payment,但許多用戶將擁有多個。 This is the output.

+0

你能根據呈現的輸出創建[JSFiddler](https://jsfiddle.net/)嗎? – Win

回答

1

你有幾個問題。首先當在Repeater/GridView中使用FindControl時,它是基於索引的。所以你需要在正確的Item上使用FindControl。

transactionGroupedList[i].FindControl("transactionCollapse") 

但是上面仍然不起作用,因爲transactionCollapse是需要被首先發現的,然後訪問正確的項目指標嵌套直放站。

transactionGroupedList.Items[0].FindControl("transactionDetailList").Items[0]... 

但是,這也將無法正常工作,因爲FindControl已不知道transactionDetailList是基於指標項目的中繼器。因此,您需要首先投射嵌套Repeater,然後才能訪問它的項目。所以它變成這樣

<%= ((Repeater)transactionGroupedList.Items[i].FindControl("transactionDetailList")).Items[i].FindControl("transactionCollapse").ClientID %>