在数据绑定期间跳过项目
问候!
我有一个使用 XmlDataSource 控件的 Repeater 控件。
<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" />
XML 看起来像这样:
<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>
在某些情况下,我想在绑定时“跳过”“B”项,以便不显示它。 在 DataBinding 事件期间,有没有办法可以跳过“B”项的绑定,以便它不会显示?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在转发器的 OnItemDataBound() 方法中调查当前的 DataItem,如果它符合您的条件,则跳过处理该项目
You could investigate the current DataItem in the OnItemDataBound() method of the repeater and skip processing that item if it matches your criteria
如果您使用的是 XmlDataSource,我建议将您的 XPath 从“Root”更改为仅包含您想要绑定的项目。
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.