Bullines
Bullines

Reputation: 5696

Skipping Items During Data Binding

Greetings!

I have a Repeater control that's using an XmlDataSource control.

<asp:FormView id="myFormView" runat="server" DataSourceID="myXmlDataSource">
    <ItemTemplate>
            <span>Items</span>
        <asp:Repeater id="myRepeater1" runat="server" DataSource='<%# XPathSelect("Items/*")%>'>
            <HeaderTemplate>
                <ul>
            </HeaderTemplate>
            <ItemTemplate>
                <li><%# XPath("text()")%></li>
            </ItemTemplate>
            <FooterTemplate>
                </ul>            
            </FooterTemplate>
        </asp:Repeater>
        <span>Things</span>
        <asp:Repeater id="myRepeater2" runat="server" DataSource='<%# XPathSelect("Things/*")%>'>
            <HeaderTemplate>
                <ul>
            </HeaderTemplate>
            <ItemTemplate>
                <li><%# XPath("text()")%></li>
            </ItemTemplate>
            <FooterTemplate>
                </ul>            
            </FooterTemplate>
        </asp:Repeater>
    </ItemTemplate>
</asp:FormView>        
<asp:XmlDataSource ID="myXmlDataSource" XPath="Root" EnableCaching="false" runat="server" />

The XML looks something like this:

<Root>
    <Items>
        <Item>A</Item>
        <Item>B</Item>
        <Item>C</Item>
        <Item>D</Item>
    </Items>
    <Things>
        <Thing>1</Thing>
        <Thing>2</Thing>
        <Thing>3</Thing>
    </Things>
</Root>

In some cases, I'd like to "skip" the "B" item when binding so that it isn't displayed. Is there a way during the DataBinding event that I could skip the binding of the "B" item so that it won't be displayed?

Upvotes: 2

Views: 1915

Answers (2)

Christian Hagelid
Christian Hagelid

Reputation: 8355

You could investigate the current DataItem in the OnItemDataBound() method of the repeater and skip processing that item if it matches your criteria

Upvotes: 3

Jarrett Widman
Jarrett Widman

Reputation: 6419

I'd recommend changing your XPath from "Root" to something that will only include items you want to bind, if you are using an XmlDataSource.

Upvotes: 3

Related Questions