开发者

.NET Itemtemplate repeater?

开发者 https://www.devze.com 2023-03-23 12:01 出处:网络
Im working on a website built in .net the following code <asp:Repeater ID=\"RT_FAQ\" runat=\"server\">

Im working on a website built in .net

the following code

<asp:Repeater ID="RT_FAQ" runat="server">
<ItemTemplate>
<div class="faq-row" style="z-index: 976;">
   <span class="itp-title"><a href="#" onclick="showhide('div1');"><%# DataBinder.Eval(Container.DataItem, "Question")%></a></span>
    <div id="div1" style="display: none;"><%# DataBinder.Eval(Container.DataItem, "Answer")%></div>
</div>
</ItemTemplate>
</asp:Repeater>

outputs something along the lines of...

<div class="faq-row" style="z-index: 976;">
    <span class="itp-title">Title</span>
    <div id="div1" style="display: none;">Div contents</div>
</div>
<div class="faq-row" style="z-index: 976;">
    <span class="itp-title">Title</span>
    <div id="div1" style="display: none;">Div contents</div>
</div>
<div class="faq-row" style="z-index: 976;">
    <span class="itp-title">Title</span>
    <div id="div1" style="display: none;">Div contents</div>
</div>
<div class="faq-row" style="z-index: 976;">
    <span class="itp-title">Title</span>
    <div id="div1" style="display: none;">Div contents</div>
</div>

If you see all the divs are being given id="div1". I need to someho开发者_如何学Gow give them all unique ID's so the first is div1, second div2 and so on.

Is this possible with .net?


Use the ItemIndex :

<div id="div<%# Container.ItemIndex %>" style="display: none;"><%# DataBinder.Eval(Container.DataItem, "Answer")%></div>

Just add + 1 if you want to start at 1 instead of 0.

0

精彩评论

暂无评论...
验证码 换一张
取 消