How to store an array

Posted by Amritha444 under ASP.NET on 1/3/2011 | Points: 10 | Views : 3327 | Status : [Member] | Replies : 3
Hi all

I want to store an array.A single value can stored in hiddenfield .like that how to store an array.I use viewstate and session but getting first value in array only.

Thanks in advance




Responses

Posted by: Madhuk on: 1/3/2011 [Member] Starter | Points: 25

Up
0
Down
Something like this will work.
Session["Arr"] = new string[] { "1", "2", "3" };

string[] ArrayLocal = (string[])Session["Arr"];
foreach (string s in ArrayLocal)
{
Response.Write(s + "<br/>");
}


Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 1/5/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Hi,

suppose TEMP is an array.
To put array into session: Session["array"]=TEMP;

and to retrive the array in another page: ArrayList temp=(System.Collections.ArrayList)Session["array"];



Thanks
Karthik
www.f5Debug.net

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prabhakar on: 1/17/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi Amritha444,


Store Array

IDictionary<int, string> values = new Dictionary<int, string>();

for (int cellIndex = 0; cellIndex < GridView1.Rows.Count; cellIndex++)
{

int questionNumber = Convert.ToInt32(cellIndex + 1);

values.Add(questionNumber, answer);
}

====== for output

Response.Write(answer + "<br>");


Best Regard's
Prabhakar

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response