views:

117

answers:

1

Hello everybody, I seems to run into problem, and not sure how to make it work. I am trying to take data from XML by using linq and the code works, however when i try use this linq data as DataSource for the ListView, i am getting an error.

How can I make it work ? How do i convert my var variable to proper variable so ListView with the Pager will accept it ?

Any examples of the code will be highly appreciated.

That is the error i am getting:

Exception Details: System.InvalidOperationException: ListView with id 'showTopics' must have a data source that either implements ICollection or can perform data source paging if AllowPaging is true.

Source Error:

Line 27:                            };
Line 28:         showTopics.DataSource = archievePosts;
Line 29:         showTopics.DataBind();
Line 30:     }
Line 31:

And the codebehind:

String xmlpath = Server.MapPath("App_Data/topics.xml");
        var archievePosts = from a in XElement.Load(xmlpath).Elements("topic")
                           where(DateTime.Parse(a.Element("topicdate").Value) <= DateTime.Parse(hDate.Text))
                           select new
                           {
                               topic_id = a.Attribute("id").Value.ToString(),
                               topic_subject = a.Element("topicname").Value,
                               topic_date = a.Element("topicdate").Value
                           };
        showTopics.DataSource = archievePosts;
        showTopics.DataBind();
+1  A: 

you can use ToArrayList() or ToList()

but are you sure that you are getting the data or there is a problem, try to debug and see the value of the ArchivePosts.

hope this helps

Yes i am sure i am getting data. I took Pager off while debugging and it was returning proper values. Going try your method now.
Dmitris
Your suggestion worked. Thank you very much.
Dmitris
anytime man, glad i have helped :)