I need to create a nested listview and found a great article on how to do it, but my situation is a bit different. I am a linq newbie and need a little help please 🙂
I need to get my data into a format similar in that article to work (on that link above, search for "Configuring the ListView" and see table right above it).
Here is my data:
Format Movie Name Price
DVD Star Wars 12.99
DVD Star Wars II 13.99
Blue-Ray Star Wars 15.99
Blue-Ray Star Wars II 17.99
Here is what I have, which isn’t really that close, but it is as far as I could get:
var MoviesToBuy = from Movie in dtMovieListDetails.AsEnumerable()
//join MovieDetails in dtMovieListDetails.AsEnumerable() on (string)Movie["ID"] equals (string)MovieDetails["ID"]
group Movie by new
{
Format = Movie["Format"],
Movies = Movie
} into grp
select new
{
Format = (string)grp.Key.Format,
Movies = grp.Key.Movies
};
MoviesToBuy = MoviesToBuy.OrderBy(p => p.Format);
lvwAmazonMovieGroup.DataSource = MoviesToBuy.ToList();
lvwAmazonMovieGroup.DataBind();
I have 3 specific issues/questions:
1.) What I have doesn’t work. Since my second column in the group equates to all rows, no actual group is created.
2.) Despite prior issue, I am also getting "Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource" error. In this case, the Movies column is being created as a DataRow datatype. Not sure if that is what is creating the problem. Can I cast on that field somehow?
3.) how can I sort on the fields in the movies. I.e. in the end I want the data to be sorted by Format then Movie Name so the nested list view looks like this:
Blue-Ray
Star Wars 12.99
Star Wars II 13.99
DVD
Star Wars 15.99
Star Wars II 17.99
Any points are greatly appreciated!
Thanks in advance,
Chad
I was thinking you could start with the following, adjusting for the proper variable names and AsEnumerable(), etc.
It orders your movies as you want and puts them in a nested structure as you requested:
Here’s an example program that implements the above query.