I received error message when run my aspx page:
"The data source for GridView with id 'GridView1' did not have any properties or attributes from which to generate columns. Ensure that your data source has content..."
I tried different code for gridview but still didn't work.
If you go into the data source configuration and add an XPath expression of "/Answers/AnswerSet/Answer" you will not get the error anymore and it will show the ID column.
Thanks for your tip. I added XPath expression as you asked. However, the output is not what I expect to see. I would like to see Yin, Yang, etc. Thanks in advance for additional input.
YinYang
Member
5 Points
23 Posts
Gridview and xmldatasource
Jan 16, 2013 04:23 PM|LINK
Hi everyone,
I received error message when run my aspx page:
"The data source for GridView with id 'GridView1' did not have any properties or attributes from which to generate columns. Ensure that your data source has content..."
I tried different code for gridview but still didn't work.
Here is xml file:
<?xml version="1.0" encoding="utf-8" ?> <Answers> <AnswerSet> <Answer ID="FName">Yin</Answer> <Answer ID="LName">Yang</Answer> </AnswerSet> <AnswerSet> <Answer ID="FName">Joann</Answer> <Answer ID="LName">Maclear</Answer> </AnswerSet> </Answers><asp:GridView ID="GridView1" runat="server" DataSourceID="XmlDataSource1" AllowPaging="True" CellPadding="4" ForeColor="#333333" GridLines="None"> <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /> <RowStyle BackColor="#FFFBD6" ForeColor="#333333" /> <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" /> <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" /> <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /> <AlternatingRowStyle BackColor="White" /> </asp:GridView> <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/answers.xml"> </asp:XmlDataSource>knieriemrt
Member
48 Points
16 Posts
Re: Gridview and xmldatasource
Jan 16, 2013 06:10 PM|LINK
If you go into the data source configuration and add an XPath expression of "/Answers/AnswerSet/Answer" you will not get the error anymore and it will show the ID column.
YinYang
Member
5 Points
23 Posts
Re: Gridview and xmldatasource
Jan 16, 2013 08:08 PM|LINK
Thanks for your tip. I added XPath expression as you asked. However, the output is not what I expect to see. I would like to see Yin, Yang, etc. Thanks in advance for additional input.
So the modified code looks like this.
<asp:XmlDataSource ID="XmlDataSource1" runat="server" XPath="/Answers/AnswerSet/Answer" DataFile="~/answers.xml"> </asp:XmlDataSource>Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Gridview and xmldatasource
Jan 18, 2013 12:49 AM|LINK
Hi,
Is your problem solved?
If yes, I'll mark it as an answer.
Otherwises please elebrate your question more clearly.
;)