Hi,
i am developting one question paper. now i want to save the question no and answer in a session using arr aylist. how can i save . in .net i am using this code i stroed both question no and answer . now i want the same code in silverlight. but in silverlight i am not getting both arraylist and sessions . how can i achieve this one.
private void SaveCheckedValues()
{
ArrayList userdetails1 = new ArrayList();
ArrayList userdetails2 = new ArrayList();
ArrayList userdetails3 = new ArrayList();
ArrayList userdetails4 = new ArrayList();
int index = -1;
foreach (GridViewRow gvrow in GV_Questionpaper.Rows)
{
index = (int)GV_Questionpaper.DataKeys[gvrow.RowIndex].Value;
bool result1 = ((RadioButton)gvrow.FindControl("RBtn_Option1")).Checked;
bool result2 = ((RadioButton)gvrow.FindControl("RBtn_Option2")).Checked;
bool result3 = ((RadioButton)gvrow.FindControl("RBtn_Option3")).Checked;
bool result4 = ((RadioButton)gvrow.FindControl("RBtn_Option4")).Checked;
if (Session["CHECKED_ITEMS1"] != null)
{
userdetails1 = (ArrayList)Session["CHECKED_ITEMS1"];
}
if (Session["CHECKED_ITEMS2"] != null)
{
userdetails2 = (ArrayList)Session["CHECKED_ITEMS2"];
}
if (Session["CHECKED_ITEMS3"] != null)
{
userdetails3 = (ArrayList)Session["CHECKED_ITEMS3"];
}
if (Session["CHECKED_ITEMS4"] != null)
{
userdetails4 = (ArrayList)Session["CHECKED_ITEMS4"];
}
if (result1)
{
if (!userdetails1.Contains(index))
userdetails1.Add(index);
}
else
{
userdetails1.Remove(index);
}
if (result2)
{
if (!userdetails2.Contains(index))
userdetails2.Add(index);
}
else
{
userdetails2.Remove(index);
}
if (result3)
{
if (!userdetails3.Contains(index))
userdetails3.Add(index);
}
else
{
userdetails3.Remove(index);
}
if (result4)
{
if (!userdetails4.Contains(index))
userdetails4.Add(index);
}
else
{
userdetails4.Remove(index);
}
Loading
Priya LingePosted Aug 25, 2011, 6:41 AM
Hi,
Make 1 class named as SessionManager class() as below,
Namespace for isolatedstorage : using System.IO.IsolatedStorage;
public class SessionManager
{
public static IsolatedStorageSettings Session = IsolatedStorageSettings.ApplicationSettings;
public static Int32 QuestionId { get; set; }
public static Int32 AnswerId { get; set; }
public SessionManager()
{
}
public SessionManager(int questionId ,Int32 ansId)
{
QuestionId = questionId ;
AnswerId = ansID;
Session.Add("questionId", questionId);
Session.Add("answeID",ansId );
}
public void clearSession()
{
Session.Clear();
}
}
Use this class in your applicarion .
if (SessionManager.Session.Contains("QuestionId"))
It return the boolean value, it check the is their value contain in session.
If(checked_items !=null)
{
new SessionManager(lblquesid.content,ansid);
Here you can get the values , suppose quesionID=lable.content,answerID=radiobtn.checked item, store this values in this class.
Hope this will help you.
Thanks.
nagarajuPosted Aug 25, 2011, 2:15 AM
i am new to this technology. i am trying from oneweek for this state issue. i done it in .net using above code . is it possible to maintain state in silverlight using this code. I think u got my requirement can u please tell me how to store the question id and answer for every page with out losing data usign isolated storage settings.
Priya LingePosted Aug 25, 2011, 12:51 AM
You can strore the values in silverlight with the help of IsoloatedStorageSettings.
Silverlight doesnot support the Arraylist. Instead of that it will supports,
the following non-generic interfaces .
•IEnumerator
•IEnumerable
•ICollection
•IComparer
•IDictionary
•IDictionaryEnumerator
•DictionaryEntry
•IEqualityComparer
•IList
http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragesettings(v=vs.95).aspx
Hope this will help you.
Thanks.