views:

34

answers:

1

I have two nested repeaters in my *.aspx page.

<asp:Repeater runat="server" id="rptMain">
    <ItemTemplate>
       <h1><%#DataBinder.Eval(Container.DataItem, "Name")%></h1>
         <asp:Repeater runat="server" DataSource='<%# getUser(Convert.ToInt32(DataBinder.Eval(Container.DataItem, "FieldKey"))) %>'>
           <HeaderTemplate><ol></HeaderTemplate>
            <ItemTemplate>
              <li class="<%#DataBinder.Eval(Container.DataItem, "CSSStyle")%>" id="li<%#DataBinder.Eval(Container.DataItem, "FieldKey")%>">
                 <%#DataBinder.Eval(Container.DataItem, "NameSubject")%>
              </li>
           </ItemTemplate>
           <FooterTemplate></ol></FooterTemplate>
         </asp:Repeater>
    </ItemTemplate>
</asp:Repeater>

getUser is a protected method. It must returns the List with the following properties:

  1. CSSClass
  2. FieldKey
  3. NameSubject

But CSSClass property is defined into the anonymous type.

protected List<????> getUser(int id)
{
  DataClassesDataContext datacontext = new DataClassesDataContext();
  var t1= from t in datacontext.GetAllCustomSubject(id).ToList()
          select new { t.NameSubject, t.FieldKey, CSSStyle = t.IsDeleted ? "deleted hidden" : "real visible" };
  return  t;
}

How can I return such List? What kind of datatype can I Use instead of ???? ? In general, can I use nested repeaters with anonymous types?

+1  A: 

Well, the repeater won't care, I suspect - so just declare it to return IEnumerable.

Jon Skeet
Could you clarify it?protected IEnumerable<what?> getUserMay be, I misunderstood it?
Amber
@Amber: Just `IEnumerable`, the non-generic type in `System.Collections`.
Jon Skeet
It works. Thank you.
Amber