2017-08-30 101 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 %>