Loop to display nested items in Repeater control?

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
 
M

Muhammad Naveed Yaseen

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;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top