c# - How to Serialize a ListItem Stored in Session -


I have this code that works fine on my local server:

  if (Page. IsPostBack) {string [] Question = New string [20]; String [] answer = new string [20]; For (int i = 0; i & lt; lstQuestions.Items.Count; ++ i) {question [i] = lstQuestions.Items [i] Text; Answer [i] = lstQuestions.Items [i]. value; } Session ["question"] = question; Session ["answer"] = answer; If (session ["qalist"] == zero) {list & lt; ListItem & gt; Qalist = lstQuestions.Items.Cast & lt; ListItem & gt; (). ToList (); Session ["qalist"] = qalist; } And {list & lt; ListItem & gt; Qalist = (list & lt; ListItem & gt;) session ["qalist"]; LstQuestions.DataSource = qalist; }} And {if (session ["question"] = null & session ["answer"]! = Null and session ["checklist"] = null] {list  catalogs> Qalist = (list   

However, when I go to a web server, I get the "System.Web.UI.WebControls.ListItem" error, which has not been said to be serializable. Is how can I make this serial, or even How can that "qalist" change as a value, which is really serial, and then saves that value to that session? However, my efforts were of no use, serializing the best route? Looking for a different way of storing data? Or something else?

UI.WebControls.ListItem is not serial, as you have seen, so you can not store it in session Are there.

I'm a little confused that you are ListItem - why two data properties are being saved and answers - In individual sessions, and also ListItem itself I think that, with the question and answering , you only need to rebuild ListItem .

But if you want to save your question and want to answer together as a pair, then you list of system.Tuple & lt; String, string & gt; , which is serialable, or even System.Web.UI.Pair , which is the serialjase.

You can also write your own (very simple) category, and mark it as serialjage:

  [serialable] public class questions and Enter {public string question {get; Set;} public string reply {get; Set; }}    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -