Kentico Repeater HTML 属性显示选定的转换

标签 kentico

我的 HTML 信封将我的转发器转换包装在 TABLE 标记中。如果不使用 JS,我如何确保此 HTML 对于所选转换不可见。我不反对为所选转换数据提供一个模板,只是不确定如何做到这一点。

这是我的转变:

<tr>
   <td><%# FormatDate(Eval("Date")) %></td>
   <td><a href="<%# GetDocumentUrl() %>"><%# Eval("Subject") %></a></td>
   <td><%# Eval("From") %></td>
</tr>

这是我选择的转换:

<section id="memoDetail">
  <h1>Memorandum</h1>
  <ul id="memoHeader">
   <li><span class="headerLabel">To:</span> <%# Eval("To") %></li>
   <li><span class="headerLabel">From:</span> <%# Eval("From") %></li>
   <li><span class="headerLabel">Subject:</span> <%# Eval("Subject") %></li>
   <li><span class="headerLabel">Date:</span> <%# Eval("Date") %></li>
  </ul>
  <div id="memoDetails"><%# Eval("Details") %></div>
</section>

最佳答案

考虑将表格标签从 html 信封中移出,并有条件地在转换中渲染它们,如下所示:

// If this is the first item in the repeater, open the table tag
<%# DataItemIndex == 0 ? "<table>" : "" %>

  // your trasformation code

// if this is the last item in the repeater, close the table tag
<%# DataItemIndex + 1 == DataItemCount ? "</table>" : "" %>

这将阻止它们出现在您所选项目的转换中,因为这是完全不同的转换。

您可能必须将 DataItemIndex 和 DataItemCount 属性放置在 Eval() 方法中。我已经有一段时间没有使用 ASCX 转换了。

编辑: 看来您现在可以在 ascx 转换中使用 IsFirst()IsLast() 方法:

<%# IsFirst() ? "<table>" : "" %>

// transformation code

<%# IsLast() ? "</table>" : "" %>

关于Kentico Repeater HTML 属性显示选定的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35435529/

相关文章:

c# - Kentico 购物车总价问题

sorting - Kentico 9 - 根据自定义字段对内容树应用排序

c# - Kentico TreeNode Delete 方法不删除依赖项

Javascript - 合并对象的属性

asp.net - 使用 Azure Blob 存储时,如何在 Kentico 中添加对 SVG 媒体文件的支持?

IIS、多个 CPU 内核、应用程序池和工作进程——单个站点的最佳配置?

c# - 中继器链接按钮 Onclick 未触发

macros - Kentico 宏获取页面类型

kentico - 如何在母版页模板中获取当前年份

javascript - 滚动条在 OS X 上的 Chrome 中不显示