code_junkie

iterate over classes ie. beans for asp.net

Nov 11th, 2011
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. [snip]
  2. <body>
  3. <form id="form1" runat="server">
  4. <% Somethings.ForEach(s => { %>
  5. <h1><%=s.Name %></h1>
  6. <h2><%=s.Id %></h2>
  7. <% }); %>
  8. </form>
  9. </body>
  10. </html>
  11.  
  12. [snip]
  13. public partial class _Default : System.Web.UI.Page
  14. {
  15. protected List<Something> Somethings { get; private set; }
  16. protected void Page_Load(object sender, EventArgs e)
  17. {
  18. Somethings = GetSomethings(); // Or whatever populates the collection
  19.  
  20. }
  21. [snip]
  22.  
  23. List<YourClass> myObjects = SomeMagicMethodThatGetsAllInstancesOfThatClassAndAddsThemtoTheCollection();
  24. foreach (YourClass instance in myObjects)
  25. {
  26. Response.Write(instance.PropertyName.ToString();
  27. }
Add Comment
Please, Sign In to add comment