Saturday, March 24, 2012

Loop to display nested items in Repeater control?

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,
SeanHi Sean,
Not sure if this is what you are looking for, have a look and let me
know.
http://www.codeproject.com/aspnet/A...edRepeaters.asp
Xke
On Mar 8, 4:46 pm, "parsifal" <sean.gilbert...@.gmail.com> wrote:
> 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;
}
On Mar 8, 4:00 pm, "xke" <xke...@.gmail.com> wrote:
> Hi Sean,
> Not sure if this is what you are looking for, have a look and let me
> know.
> http://www.codeproject.com/aspnet/A...edRepeaters.asp
> Xke
> On Mar 8, 4:46 pm, "parsifal" <sean.gilbert...@.gmail.com> wrote:
>
>
>
>
>
>
> - Show quoted text -
Hi!
Yes this is getting at exactly what I want. Thank you! :-) I also
found this article from Microsoft:
http://support.microsoft.com/kb/306154
Thanks again!
Sean :-)
good to hear that

0 comments:

Post a Comment