Repeater's SeparatorTemplate with Eval

隐身守侯 提交于 2019-12-05 13:14:39

Try this:

Add a private variable (or two) in the class of your WebForm that you can use to increment/track what the flight information is while you are performing your databinding at the item level.

Then in the ItemDatabound event, you can perform a simple evaluation if the item being databound is the ListItemType.Seperator type and display/hide/modify your seperator code that way.

Your WebForm page would look something like this at the top:

public partial class ViewFlightInfo : System.Web.UI.Page
{

    private int m_FlightStops;

    protected page_load
    {

        // Etc. Etc.

    }
}

Then when you get down to your 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 to this effect.

Hey, I'll settle with a way to identify the last item in the repeater so that I can avoid generating the 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!