Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Following is the code

SPList splist = web.Lists["MyList"];

var query = from SPListItem oItem in splist.Items.OfType<SPListItem>()
                            where !Convert.ToString(oItem["Status"]).Equals("Completed")
                            select oItem;

List<SPListItem> value = query.ToList<SPListItem>();

upto here working perfectly..

Now store value into viewstate getting following exception

ViewState.Add("Key", value);

Exception

System.Runtime.Serialization.SerializationException: Type 'Microsoft.SharePoint.SPListItem' in Assembly 'Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' is not marked as serializable.

Thanks

share|improve this question
    
The result of this query is SPListItems which are not serializable and cannot be added to the ViewState. This query may return a large amount of items and it is not recommended to save them in ViewState. What are you trying to achieve? Maybe there is a better way. –  user3470 Dec 5 '12 at 5:55
    
i want get same linq query result during button click event bcz i don't trip to database(SPList) again. –  Hitesh Chandegara Dec 5 '12 at 13:53
    
@hitz Do the query again on button click instead of saving in ViewState! –  Arsalan Adam Khatri Dec 5 '12 at 14:11
    
You really should be running a CAML query. Using linq fetches all the items in the list before filtering them. If you have thousands of items, this will kill the server –  Grooverinthesouth Dec 5 '12 at 16:40
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.