I have a simple XML document with data needed to fill in an HTML template. Using C#, how do I pull the data and fill in an HTML template page?
Assuming:
string baseurl = "http://mysite.com/page.aspx?id=";
XML Data – Data.xml:
<container>
<item>
<name>Clark</name>
<id>10</id>
<range>week</type>
</item>
<item>
<name>Cowlitz</name>
<id>11</id>
<range>daily</range>
</item>
</container>
HTML Template – Default.aspx:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<h3><%# Eval("Name") %></h3>
<img src="<% baseurl %><%# Eval("id") %>
&range=<%# Eval("range") %>" alt="<%# Eval("name") %>" />
</ItemTemplate>
</asp:Repeater>
I apologize for the simple question, but I simply cannot find a good recipe for this task. I’m not sure if I should use a repeater, or if I should format all the HTML in the codebehind and then dump it into something like a Literal.
This was a fairly simple task using my prior language, but with C#, I’m finding that there are many ways of handling XML, and I’m really not sure which one I should pursue for such a limited and seemingly simple task.
Thanks for any advice.
Dan
You should look at the
XmlDataSourceclass. There are numerous good tutorials around the place.