xml attribure in dataset

Posted by raging_boner on Stack Overflow See other posts from Stack Overflow or by raging_boner
Published on 2010-05-23T19:42:11Z Indexed on 2010/05/23 19:51 UTC
Read the original article Hit count: 285

Filed under:
|
|
|
|

I want to bind Repeater control to Dataset which is filled with XML data, but i don't know how to show attributes inside repeater.

Xml File:

<root>
   <items>
      <item id="9" name="111111111111" description="111111245" views="1"  galleryID="0" />
   </items>
</root>

Repeater code:

<asp:Repeater ID="rptrGalleries" runat="server">
   <ItemTemplate>
      <a href='Page?id=<%#DataBinder.Eval(Container.DataItem, "id") %>'><%#DataBinder.Eval(Container.DataItem, "name") %></a>
   </ItemTemplate>
</asp:Repeater>

Codebehind:

XDocument doc = XDocument.Load(Server.MapPath("~/xml/gallery.xml"));

        IEnumerable<XElement> items = from item in doc.Descendants("item")
                                      orderby Convert.ToDateTime(item.Attribute("lastChanges").Value) descending
                    where int.Parse(item.Attribute("galleryID").Value) == 0 && bool.Parse(item.Attribute("visible").Value) != false
                    select item;
        DataSet ds = new DataSet();
        ds.ReadXml(new StringReader(doc.ToString()));

        rptrGalleries.DataSource = ds;
        rptrGalleries.DataBind();

When I compile site I receive this error:

System.Web.HttpException: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'id'.

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET