Loop to display nested items in Repeater control?

  • Thread starter Thread starter parsifal
  • Start date Start date
P

parsifal

Hi everyone :-)

I am learning to use the Repeater control to display a list of data.
Each of my list items (or rows, however you look at it) has some child
items that are 1..N in length. So I'd like to be able to - within the
Repeater's ItemTemplate - loop over those child elements and display
some controls for each.

Right now I'm simply trying to do a loop (e.g. <% For Each stuff as
String in Eval("Things") ... Next %>, but that does not work. And I
don't believe that's what Eval is meant for (item retrieval). Anyway,
the error it gives is: "Databinding methods such as Eval(), XPath(),
and Bind() can only be used in the context of a databound control."

How do I go about doing this?

Thanks,
Sean
 
the error it gives is: "Databinding methods such as Eval(), XPath(),
and Bind() can only be used in the context of a databound control."

It is saying Eval, XPath or Bind can only be used in dynamic
assignment (i.e <%# %>) of property of a data-bindable control, which
is different than a <% %> block.

And contents of <%# %> must evaluate to an object of type convertible
to property being assigned. Conditional or looping statements do not
evaluate to objects.

Nested repeater may be one way to go if appropriate.
If it is simply repeating or transforming something, try following.

<asp:Literal runat="server" id="ltlSomeLiteral"
EnableViewState="false" Text="<%# SomeFunction( Eval("Thing")) %>' />

with code behind

protected string SomeFunction(TypeOfThings input)
{
string ouput = string.Empty;
foreach(string stuff in input) // presuming input is IEnumberable
{
.....
}
return output;
}
 
Back
Top