English 中文(简体)
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;
}
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签