-1

How can i use it in Repeater ItemTemplate ?

foreach(string tag in Eval("etiketler"))
{
    Response.Write("<a href='#'>"+tag+"</a");
}

3 Answers 3

2

there is no way to do it in this format. you should send Dataitem to a static method and then you should return string that contains your markup..

public static string GetMarkup(object dataItem)
{
    var tags = DataBinder.Eval(dataItem, "etiketler"); // depend on etiketler type

    StringBuilder sb = new StringBuilder();
    foreach(string tag in tags) 
    { 
        sb.Append("<a href='#'>"+tag+"</a"); 
    }

    return sb.ToString();
}

use this method like this:

<%# GetMarkup(Container.DataItem) %>
1

<%# is not made to use foreach with it, neither if or other language keywords. It's mainly done to databinding.

But you can :

Hope this helps

0

You can also use nested repeaters in ASP.NET

<asp:Repeater runat="server" ID="rpt1">
  <ItemTemplate>
     <asp:Repeater runat="server" ID ="rpt2" DataSource='<%# Eval("etiketler") %>'>
      <ItemTemplate>
        <%# Eval("tag") %>
     </ItemTemplate>
    </asp:Repeater>
  </ItemTemplate>
</asp:Repeater>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.