XmlDataSource in UserControl not loading
I have a very simple user control with an xmldatasource that binds to a repeater which looks something like:
XmlDataSource xmlFeed =
new
XmlDataSource();
xmlFeed.DataFile =
"www.example.com/books.xml"
;
xmlFeed.CacheDuration = 900;
rp.DataSource = xmlFeed;
rp.DataBind();
Hi Al,
I have created such control that reads xml feeds, rss feeds and also xml files placed in App_Data with minor changes. Please refer to the code I hope it will help you.
The .ascx file:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="XML.ascx.cs" Inherits="SitefinityWebApp.Custom.XML" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<
asp:XmlDataSource
ID
=
"XmlDataSource1"
runat
=
"server"
>
</
asp:XmlDataSource
>
<
asp:Repeater
ID
=
"Repeater1"
runat
=
"server"
DataSourceID
=
"XmlDataSource1"
>
<
ItemTemplate
>
<%#XPath("link")%>"> <%#XPath("title")%>
</
ItemTemplate
>
<
SeparatorTemplate
>
<
hr
/>
</
SeparatorTemplate
>
</
asp:Repeater
>
XmlDataSource1.DataFile = "http://www.eyefootball.com/rss_news_main.xml";
XmlDataSource1.XPath = "rss/channel/item";
XmlDataSource1.Data= "XmlDataSource1";
XmlDataSource1.DataBind();
Hi Stanislav,
Has there been any word from Sitefinity about documentation with the XML widget? I am trying to find resources regarding this, but I am coming up short.
I'm new to .NET and Sitefinity itself, so I am somewhat lost on your post. I did create the .ascx file, and I have my xml file. However, I have 2 follow-up questions:
1. For the .cs codebehind, where does your code specifically go? Visual Studio adds start-up code, and I'm not sure where to place the XmlDataSource1.DataFile code.
2. With this code established, how do I connect this data with the XML Data Source widget in Sitefinity? What settings do I use in the dialog box window after a drag out of the widget onto my page?
I would appreciate any help anyone can offer. Thank you so much,
Maria
Hello Maria,
There is no documentation on XML Data source control as its just standard XmlDataSource ASP.NET control registered in Sitefintiy.
It is a lot more easier to use the asp.net XmlDataSource to address scnarious where you need to get xml data displayed as in the sample control from my previous reply.
To use XmlDataSource sitefinity widget place it on a page and give when editing it give it some ID meaningfull to you.
Second create user control and when you need access to XMl data put the ID of the XmlDataSource control as datasource.
This is just saving you the usage of XmlDataSource
<
asp:XmlDataSource
ID
=
"XmlDataSource1"
runat
=
"server"
>
</
asp:XmlDataSource
>
namespace
SitefinityWebApp
public
partial
class
TestWebForm : System.Web.UI.Page
protected
void
Page_Load(
object
sender, EventArgs e)
XmlDataSource1.DataFile =
"http://www.eyefootball.com/rss_news_main.xml"
;
XmlDataSource1.XPath =
"rss/channel/item"
;
XmlDataSource1.Data=
"XmlDataSource1"
;
XmlDataSource1.DataBind();