开发者

Anonymous type for nested repeater (ASP .NET)

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='<%# 开发者_Go百科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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜