Guest User

Guest User

  • Tech Writer
  • 4
  • 0

xml attribure in dataset

May 24 2010 3:15 AM

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")
                   
where int.Parse(item.Attribute("galleryID").Value) == 0
                   
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'.


Answers (3)