ASP.NET直放站模板,条件code,每第N个元素 [英] ASP.NET Repeater Template, Conditional Code for every Nth element

查看:155
本文介绍了ASP.NET直放站模板,条件code,每第N个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用一个asp.net中继器来创建一批图像。图像标记都是一样的,所以标准的<的ItemTemplate方式>

I'm using an asp.net repeater to create a bunch of images. The image markup is all the same so the standard <ItemTemplate> is fine.

不过,我想在一个div包裹ķ图像。可以说,我绑定25+图像到中继器,我想每格5张图片。我怎么去建立有条件的DIV开始和关闭标签?

However, I want to wrap K images in a div. Lets say I bind 25+ images to the repeater and I want 5 images per div. How do I go about conditionally creating the start and close tags for the div?

这是一个案例一个更适合循环。

Is this a case better suited for a for loop.

推荐答案

这应该为你工作,而无需在code什么东西(除了绑定中继器等..):

This should work for you, with no need for anything in the code behind (other than binding the repeater..):

<asp:Repeater ID="repImages" runat="server">
<HeaderTemplate><div></HeaderTemplate>

<ItemTemplate>
<%# (Container.ItemIndex != 0 && Container.ItemIndex % 5 == 0) ? @"</div><div>" : string.Empty %>
<asp:Image ID="imgGallery" runat="server" ImageUrl='<%# /* your code  here */ %>' />
</ItemTemplate>

<FooterTemplate></div></FooterTemplate>
</asp:Repeater>

这篇关于ASP.NET直放站模板,条件code,每第N个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆