G
Guest
I am trying to create a session array then use the array in a foreach. I get
an error saying: "foreach statement cannot operate on variables of type
'object' because 'object' does not contain a definition for 'GetEnumerator',
or it is inaccessible"
The session is necessary because of postback
There are three steps here:
1. populate an array.
2. copy the array to a session array.
3. do foreach om the session array.
//step 1.-------------------------------
private void Save_Click(object sender, System.EventArgs e)
{
enrarray.Add(new
EnrollList(progid,Int32.Parse(Session["enroleeid"].ToString()),Int32.Parse(Session["sessionid"].ToString()),Int32.Parse(Session["classid"].ToString()),Int32.Parse(Session["tsid"].ToString()),Session["enrolee"].ToString(),Session["sessnm"].ToString(),Session["classnm"].ToString(),Session["tslot"].ToString()));
//step 2-----------------
Session["enr"]=enrarray;
}
//step 3-----------------------
private void Button1_Click(object sender, System.EventArgs e)
{
this.messagebox.Text="records "+enrarray.Count.ToString();
foreach(EnrollList tmp in Session["enr"])
{
tmp.saveenrl();
}
}
//error message---------------------------
c:\inetpub\wwwroot\BrighamPR\Enroll.aspx.cs(481): foreach statement cannot
operate on variables of type 'object' because 'object' does not contain a
definition for 'GetEnumerator', or it is inaccessible
Thanks in advance
NZ
an error saying: "foreach statement cannot operate on variables of type
'object' because 'object' does not contain a definition for 'GetEnumerator',
or it is inaccessible"
The session is necessary because of postback
There are three steps here:
1. populate an array.
2. copy the array to a session array.
3. do foreach om the session array.
//step 1.-------------------------------
private void Save_Click(object sender, System.EventArgs e)
{
enrarray.Add(new
EnrollList(progid,Int32.Parse(Session["enroleeid"].ToString()),Int32.Parse(Session["sessionid"].ToString()),Int32.Parse(Session["classid"].ToString()),Int32.Parse(Session["tsid"].ToString()),Session["enrolee"].ToString(),Session["sessnm"].ToString(),Session["classnm"].ToString(),Session["tslot"].ToString()));
//step 2-----------------
Session["enr"]=enrarray;
}
//step 3-----------------------
private void Button1_Click(object sender, System.EventArgs e)
{
this.messagebox.Text="records "+enrarray.Count.ToString();
foreach(EnrollList tmp in Session["enr"])
{
tmp.saveenrl();
}
}
//error message---------------------------
c:\inetpub\wwwroot\BrighamPR\Enroll.aspx.cs(481): foreach statement cannot
operate on variables of type 'object' because 'object' does not contain a
definition for 'GetEnumerator', or it is inaccessible
Thanks in advance
NZ