Click to See Complete Forum and Search --> : sending collection through a session variable


novice_andrei
September 21st, 2007, 02:26 PM
Hello.

I am trying to send data from a datagrid in an .aspx (first.aspx) page, into the empty datagrid from another .aspx page (second.aspx). I thought of doing this by creating a session variable on the first.aspx which loads the data into a collection<> and is sent to the second.aspx page from where another collection<> takes it.


First question is: is this what I need to do for passing data between datagrids in different pages? By using session vars? Is it actually valid to pass a collection into a session?

Second question, here is the syntax I used which does not compile:

On first.aspx page:

protected void SendToSession()
{
Collection<MyClass> sendToSession = MyClass.LoadAllDataFromSQL();
Session["Group"] = sendToSession;
Response.Redirect("second.aspx",false);
}


On second.aspx page:


private void ReceiveFromSession()
{
Collection<MyClass> sessionCol = (Collection<MyClass>)Session["Group"];
gridSelectedMails.DataSource = sessionCol;
gridSelectedMails.DataBind();
}


The error I get is regarding the second.aspx:

FormatException unhandled by user code:
Input string was not in a correct format.


What would be the correct syntax for this?
Thank you in advance.

novice_andrei
September 22nd, 2007, 01:10 PM
i was missing the correct cast....

it is amazing what a good night's sleep can do.
sorry for the trouble, its ok now.