Repeater Separator

Can I use Eval or similar syntax in the SeparatorTemplate of the repeater?

Id 'would like to display some information about the last element in the delimiter pattern, for example:

<table> <asp:Repeater> <ItemTemplate> <tr> <td><%# Eval("DepartureDateTime") %></td> <td><%# Eval("ArrivalDateTime") %></td> </tr> </ItemTemplate> <SeparatorTemplate> <tr> <td colspan="2">Change planes in <%# Eval("ArrivalAirport") %></td> </tr> </SeparatorTemplate> <asp:Repeater> <table> 

Skipping that it will generate something like this:

 <table> <asp:Repeater> <tr> <td>2009/01/24 10:32:00</td> <td>2009/01/25 13:22:00</td> </tr> <tr> <td colspan="2">Change planes in London International Airport</td> </tr> <tr> <td>2009/01/25 17:10:00</td> <td>2009/01/25 22:42:00</td> </tr> <asp:Repeater> <table> 

But the SeparatorTemplate seems to ignore the Eval () call. I also tried using the previous syntax as follows: <% # DataBinder.Eval (Container.DataItem, "ArrivalAirport")%> with the same results.

Is it possible to display the information of the previous item in a SeparatorTemplate? If not, can you suggest an alternative way to generate this code?

thanks

+4
source share
2 answers

Try the following:

Add a private variable (or two) to your WebForm class, which you can use to increase / track flight information while you bind data at the position level.

Then, in the ItemDatabound event, you can perform a simple evaluation if the data item is of type ListItemType.Seperator and displays / hides / changes your separator code in this way.

Your WebForm page will look something like this:

 public partial class ViewFlightInfo : System.Web.UI.Page { private int m_FlightStops; protected page_load { // Etc. Etc. } } 

Then, when you go to data binding:

 protected void rFlightStops_ItemDataBound(object sender, RepeaterItemEventArgs e) { Repeater rFlightStops = (Repeater)sender; if (e.Item.ItemType == ListItemType.Header) { // Initialize your FlightStops in the event a new data binding occurs later. m_FlightStops = 0; } if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { // Bind your Departure and Arrival Time m_FlightStops++; } if (e.Item.ItemType == ListItemType.Seperator) { if (m_FlightStops == rFlightStops.Items.Count - 1) { PlaceHolder phChangePlanes = (PlaceHolder)e.Item.FindControl("phChangePlanes"); phChangePlanes.Visible = false; } } } 

... or something like that.

+2
source

Hey, I agree to identify the last element in the repeater so that I can avoid creating a separator there:

 <table> <asp:Repeater> <ItemTemplate> <tr> <td><%# Eval("DepartureDateTime") %></td> <td><%# Eval("ArrivalDateTime") %></td> </tr> <% if (<<<isn't the last item>>) { %> <tr> <td colspan="2">Change planes in <%# Eval("ArrivalAirport") %></td> </tr> <% } %> </ItemTemplate> <asp:Repeater> <table> 

thanks

0
source

All Articles