J
Jakub Èermák
Hello *,
I'm still making my first steps in asp.net so please forgive me, if my
problem is trivial.
I've GridView and I wanna to use an IEnumerable from LINQ as its datasource.
When I do
GrivView1.DataSource=from i in xdoc.Root.Element("channel").Elements("item")
select new {
Url = i.Element("link").Value,
Description = i.Element("description").Value,
Title = i.Element("title").Value,
PubTime = DateTime.Parse(i.Element("pubDate").Value)
};
everything works as expected. But when I replace the anonymous type with
normal class it stops working: "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. "
Even when I turn off the autogeneratecolumns and make the colums by hand, it
can't find them.
The source code:
GrivView1.DataSource=from i in xdoc.Root.Element("channel").Elements("item")
select new RSSRecord()
{
Url = i.Element("link").Value,
Description = i.Element("description").Value,
title = i.Element("title").Value,
PubTime = DateTime.Parse(i.Element("pubDate").Value)
};
and the RSSRecord class:
public class RSSRecord
{
public string Url,title,Description;
public DateTime PubTime;
}
What can be wrong in the 2nd code, when the 1st code works well? I don't get
the difference.
Thanks in advance for your help.
Jakub Èermák
P.S.: It's just testing/learning code, so please don't comment the variable
names and code structure![Smile :) :)](/styles/default/custom/smilies/smile.gif)
I'm still making my first steps in asp.net so please forgive me, if my
problem is trivial.
I've GridView and I wanna to use an IEnumerable from LINQ as its datasource.
When I do
GrivView1.DataSource=from i in xdoc.Root.Element("channel").Elements("item")
select new {
Url = i.Element("link").Value,
Description = i.Element("description").Value,
Title = i.Element("title").Value,
PubTime = DateTime.Parse(i.Element("pubDate").Value)
};
everything works as expected. But when I replace the anonymous type with
normal class it stops working: "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. "
Even when I turn off the autogeneratecolumns and make the colums by hand, it
can't find them.
The source code:
GrivView1.DataSource=from i in xdoc.Root.Element("channel").Elements("item")
select new RSSRecord()
{
Url = i.Element("link").Value,
Description = i.Element("description").Value,
title = i.Element("title").Value,
PubTime = DateTime.Parse(i.Element("pubDate").Value)
};
and the RSSRecord class:
public class RSSRecord
{
public string Url,title,Description;
public DateTime PubTime;
}
What can be wrong in the 2nd code, when the 1st code works well? I don't get
the difference.
Thanks in advance for your help.
Jakub Èermák
P.S.: It's just testing/learning code, so please don't comment the variable
names and code structure
![Smile :) :)](/styles/default/custom/smilies/smile.gif)