code_junkie

Repeater's SeparatorTemplate with Eval

Nov 13th, 2011
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. <table>
  2. <asp:Repeater>
  3. <ItemTemplate>
  4. <tr>
  5. <td><%# Eval("DepartureDateTime") %></td>
  6. <td><%# Eval("ArrivalDateTime") %></td>
  7. </tr>
  8. </ItemTemplate>
  9. <SeparatorTemplate>
  10. <tr>
  11. <td colspan="2">Change planes in <%# Eval("ArrivalAirport") %></td>
  12. </tr>
  13. </SeparatorTemplate>
  14. <asp:Repeater>
  15. <table>
  16.  
  17. <table>
  18. <asp:Repeater>
  19. <tr>
  20. <td>2009/01/24 10:32:00</td>
  21. <td>2009/01/25 13:22:00</td>
  22. </tr>
  23. <tr>
  24. <td colspan="2">Change planes in London International Airport</td>
  25. </tr>
  26. <tr>
  27. <td>2009/01/25 17:10:00</td>
  28. <td>2009/01/25 22:42:00</td>
  29. </tr>
  30. <asp:Repeater>
  31. <table>
  32.  
  33. public partial class ViewFlightInfo : System.Web.UI.Page
  34. {
  35.  
  36. private int m_FlightStops;
  37.  
  38. protected page_load
  39. {
  40.  
  41. // Etc. Etc.
  42.  
  43. }
  44. }
  45.  
  46. protected void rFlightStops_ItemDataBound(object sender, RepeaterItemEventArgs e)
  47. {
  48. Repeater rFlightStops = (Repeater)sender;
  49.  
  50. if (e.Item.ItemType == ListItemType.Header)
  51. {
  52. // Initialize your FlightStops in the event a new data binding occurs later.
  53. m_FlightStops = 0;
  54. }
  55.  
  56. if (e.Item.ItemType == ListItemType.Item
  57. || e.Item.ItemType == ListItemType.AlternatingItem)
  58. {
  59. // Bind your Departure and Arrival Time
  60. m_FlightStops++;
  61. }
  62.  
  63. if (e.Item.ItemType == ListItemType.Seperator)
  64. {
  65. if (m_FlightStops == rFlightStops.Items.Count - 1)
  66. {
  67. PlaceHolder phChangePlanes =
  68. (PlaceHolder)e.Item.FindControl("phChangePlanes");
  69. phChangePlanes.Visible = false;
  70. }
  71. }
  72. }
  73.  
  74. <table>
  75. <asp:Repeater>
  76. <ItemTemplate>
  77. <tr>
  78. <td><%# Eval("DepartureDateTime") %></td>
  79. <td><%# Eval("ArrivalDateTime") %></td>
  80. </tr>
  81. <% if (<<<isn't the last item>>) { %>
  82. <tr>
  83. <td colspan="2">Change planes in <%# Eval("ArrivalAirport") %></td>
  84. </tr>
  85. <% } %>
  86. </ItemTemplate>
  87. <asp:Repeater>
  88. <table>
  89.  
  90. <table>
  91. <asp:Repeater ID="rFlightStops" runat="server"
  92. OnItemDataBound="rFlightStops_ItemDataBound">
  93. <ItemTemplate>
  94. <tr>
  95. <td><%# Eval("DepartureDateTime") %></td>
  96. <td><%# Eval("ArrivalDateTime") %></td>
  97. </tr>
  98. <asp:PlaceHolder ID="phChangePlanes" runat="server">
  99. <tr>
  100. <td colspan="2">Change planes in <%# Eval("ArrivalAirport") %></td>
  101. </tr>
  102. </asp:PlaceHolder>
  103. </ItemTemplate>
  104. <asp:Repeater>
  105. <table>
  106.  
  107. protected void rFlightStops_ItemDataBound(object sender, RepeaterItemEventArgs e)
  108. {
  109. Repeater rFlightStops = (Repeater)sender;
  110. if (e.Item.ItemType == ListItemType.Item
  111. || e.Item.ItemType == ListItemType.AlternatingItem)
  112. {
  113. if (e.Item.ItemIndex == rFlightStops.Items.Count - 1)
  114. {
  115. PlaceHolder phChangePlanes =
  116. (PlaceHolder)e.Item.FindControl("phChangePlanes");
  117. phChangePlanes.Visible = false;
  118. }
  119. }
  120. }
Add Comment
Please, Sign In to add comment