C
Celine
is it possible to pass an arraylist from one page to another page? If yes how?
(I'm using asp.net and c#)
(I'm using asp.net and c#)
Hi Morten, Thank you for your answer but I am getting an error
message: "Object reference not set to an instance of an object."
I am trying to build a pictures gallery. For that I display in
datalist thumbnails(form1) which the user can clicked to display a
larger picture. As the larger images are displayed in another web
form(form2) I need to store the pictures numbers the user has already
selected and display them back again on the first page(form1).
My code is as follow:
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
BindGrid();
someArrayList = (ArrayList)Session["List"];
for(int i=0;i<someArrayList.Count;i++)
{
PicsDDL.Items.Add(someArrayList.ToString());
}
}
}
private void DataList1_ItemCommand(object source,
System.Web.UI.WebControls.DataListCommandEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
Label Lbl=(Label)e.Item.FindControl("NameLbl");
Button Btn=(Button)e.Item.FindControl("addBtn");
ImageButton imBtn=(ImageButton)e.Item.FindControl("imageBtn");
if(e.CommandName=="select")
{
for(int i=0;i<PicsDDL.Items.Count;i++)
{
arrayPics.Add(PicsDDL.Items.Text);
}
Session["List"] = arrayPics;
}
if(e.CommandName=="AddToBasket")
{
PicsDDL.Items.Add( Lbl.Text);
}
}
I would really appreciate if you can help me. I am really confused
because when I try to access the array on the form2(where larger
pictures are displayed) I get no error message. It is only when I try
to access it on form1.
Celine
Morten Wennevik said:Hi Celine,
Yes, you can pass any object between pages. Just store them as Session or Application objects.
Session["List"] = myArrayList;
someArrayList = (ArrayList)Session["List"];