Posted By

the_menace on 03/01/10


Tagged

c aspnet


Versions (?)

ASP.NET - Loop through the ListView Control.


 / Published in: C#
 

Loop through the ListView Control within 2nd level collection. 2nd level means it's within another control (ie table html generic control).

  1. // #1 - Loop through the ListView control (level 1 == index)
  2. for (int i = 0; i < ListView1.Controls[0].Controls[1].Controls.Count; i++)
  3. {
  4. Response.Write(ListView1.Controls[0].Controls[1].Controls[i] + "<br>");
  5. }
  6.  
  7. // #2 - Databound (level 1 == index)
  8. for (int i = 0; i < e.Item.Controls.Count; i++)
  9. {
  10. Response.Write(e.Item.Controls[i].ID + "<br>");
  11. }
  12.  
  13. // #3 - Iterate through each row collection
  14. for (int i = 0; i < ListView1.Items.Count + 1; i++)
  15. {
  16. // Each control on a row
  17. Response.Write(ListView1.Controls[0].Controls[1].Controls[i] + "<br>");
  18. // Control collection per row
  19. ControlCollection c = ListView1.Controls[0].Controls[i].Controls;
  20. }

Report this snippet  

You need to login to post a comment.