views:

188

answers:

2

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?

+3  A: 

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.

jarrett
+3  A: 

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

Christian Hagelid
I was thinking that might the best answer, would you just override the OnItemDataBound and choose to omit calling it's base method when you find an item you wish to omit?
Neil Trodden
How is "skip processing" accomplished?
Bullines
I think I answered my own question: by setting the DataItem's visibility to false.
Bullines