0

我正在构建一个基于引导的手风琴。它几乎就在那里,除了我需要用一个带有唯一 ID 的标签来包装每个手风琴。我的想法是使用中继器控件 ID。那么我如何从转换以及 HTML 信封中访问它呢?

这是转发器的 HTML 信封

<div class="accordion" id="askUsAccordion">
  
  
</div>

这是我的转换代码

<div class="panel panel-default">
  <div class="panel-heading">
    <h4 class="panel-title">
      <a href="#accordionPanel<%# DataItemIndex + 1 %>" data-toggle="collapse" data-parent="#"><%# DataItemIndex + 1 %> <%# Eval("Heading") %></a>
    </h4>    
  </div>  
  <div id="accordionPanel<%# DataItemIndex + 1 %>" class="panel-collaspe collapse" role="tabpanel" aria-labeledby="panel<%# DataItemIndex + 1 %>">
    <div class="panel-body">
      <%# Eval("Panel") %>
    </div>
  </div> 
</div>  

4

3 回答 3

3

为什么不直接使用Repeater 的ClientID?

在这种情况下尝试 <%# Container.ClientID %> Container 应该引用正在运行转换的中继器。

于 2016-02-23T18:27:31.373 回答
2

马克,不确定这是最好的解决方案,但它应该适合你。将服务器端功能添加到您的转换中,如下所示:

<script runat="server">
  protected string GetID()
    {      
      Control parent = this;      
      while ( (!(parent is CMSWebParts_Viewers_Documents_cmsrepeater)) && 
             (parent != null))
      {
        parent = parent.Parent;
      }      
      return (parent as CMSWebParts_Viewers_Documents_cmsrepeater).WebPartID;
    }
</script>

并在您的转换中调用此方法,如下所示:

<%# GetID() %>
于 2016-02-23T14:27:18.627 回答
0

虽然这不是我喜欢的方法,但我写了一个快速的 js 片段。我尽量避免有太多的 JS。

  /* Accordions */
  // we first detect if there is an accordion in the DOM, and if see we ensure that each is with it's own names space
  if ($accordion.length){
    // we need the ID of each accordion on the page which then becomes the data-parent value, which is needed to ensure we can isolate accordions
    $accordion.each(function(i,v){
      var $this = $(this),
          $id = $this.attr('id');
      // loop through each accordion panel
      $this.children('.panel').each(function(){
        var $that = $(this);
        $('.panel-title-link', $that).attr('data-parent', $id);
      });
    });
  }

于 2016-02-23T15:18:34.250 回答