I’ve been trying to find out how I could simply reverse the data I get from an xml/order it by date or if I can do that withing the repeater, which renders them on the page.
So here is what I have:
Simply the page reads an xml…
if (!Page.IsPostBack)
{
DataSet messages = new DataSet();
try
{
messages.ReadXml(MapPath("~/_xml/messages.xml"));
myMessages.DataSource = messages;
myMessages.DataBind();
}
…and puts the date in a DataSet.
On the page, a repeater renders the data…
<asp:Repeater ID="myMessages" runat="server">
<HeaderTemplate>
<table border="0">
</HeaderTemplate>
<ItemTemplate>
<div class="message">
<div class="messageHeader">
<span><p><b><%# DataBinder.Eval(Container.DataItem, "name") %></b> wrote <%# DataBinder.Eval(Container.DataItem, "date") %>:</p></span>
</div>
<div class="splitLine"></div>
<br />
<div class="messageText">
<span><p><%# DataBinder.Eval(Container.DataItem, "message") %></p></span>
</div>
</div>
</ItemTemplate>
<FooterTemplate>
</Table>
</FooterTemplate>
</asp:Repeater>
Maybe it’s also possible to just write the data in a different order, like instead of putting new entries to the end of the file just put them at the beginning. But I think that’s not really a solution.
So this is how I write the data into an xml:
var file = Server.MapPath("~/_xml/messages.xml");
var message = new XElement("contact",
new XElement("Name", s_name.Trim()),
new XElement("message", s_message.Trim()),
new XElement("date", DateTime.Now.ToString()));
var doc = new XDocument();
if (ckeckFileExistance(file))
{
doc = XDocument.Load(file);
doc.Element("messages").Add(message);
}
else
{
doc = new XDocument(new XElement("messages", message));
}
doc.Save(file);
It’s a quick and small project. It should be as simple as possible. And again. What I want to do is to make the newest entries appear on the top of the page. Now they appear on the bottom.
Thanks in advance!
and change the repeater bindings to
etc