开发者

Xpath within ItemDataBound for Repeater

Okay so I'm pulling in an XML feed from feedburner, using an XMLDataSource and a repeater.

<asp:Repeater ID="rptrEvents" OnItemDataBound="rptrEvents_ItemDataBound" DataSourceID="XmlDataSource1" runat="server">
    <ItemTemplate>
            <li runat="server" id="liLineItem">
                <a href="<%#XPath("link")%>">
                    <span><%#XPath("pubdate")%></span>
                    <%#XPath("title")%>
                </a>
            </li>
    </ItemTemplate>
</asp:Repeater>

Now the problem I'm running into is, "pubdate" is empty, and title includes both the title and date [though it can easily be split because the date always ends in a : (colon)

So I need to be able to do this in the code 开发者_如何转开发behind.

However, I'm unable to get this to work in the code behind.

I've tried something like this (now granted, I'm a total newb when it comes to XML)

IXPathNavigable x = (IXPathNavigable)e.Item.DataItem;
XPathNavigator nav = x.CreateNavigator();

XmlElement xePage = (XmlElement)nav.UnderlyingObject;
string title = xePage.GetAttribute("title");

So I tried this, but xePage always shows "HasAttributes" as false, and never finds the title. xePage.InnerXML seems to contain the proper data, but I don't want to try and parse things out manually.

Can anyone point me in a better direction on what I'm doing wrong?

Thanks!


In your OnItemBound event try this instead.

protected void Repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    IXPathNavigable x = (IXPathNavigable)e.Item.DataItem;
    XPathNavigator nav = x.CreateNavigator();
    XmlElement xePage = (XmlElement)nav.UnderlyingObject;
    string title = xePage.SelectSingleNode("title").InnerText;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜