473,405 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

passing arraylist

is it possible to pass an arraylist from one page to another page? If yes how?
(I'm using asp.net and c#)
Nov 16 '05 #1
3 2039
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"];

--
Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2
Hi Celine,

You need to store some list under the "List" name when you start the session.
I'm not sure this will work (not too familiar with web programs) but you could try

if(Session["List"] != null)
{
//there is a list available
someArrayList = (ArrayList)Session["List"];
}
else
{
Session["List"] = new ArrayList();
}

Note that the name "List" could be anything, so you could store several list under different names.

--
Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #3
Hi Morten, Thank you for so much your help. Everything is working fine now!!
Celine

sq*****@yahoo.fr (Celine) wrote in message news:<f3************************@posting.google.co m>...
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[i].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[i].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" <Mo************@hotmail.com> wrote in message news:<opsc3d0xhnklbvpo@ubuan>...
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"];

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: David | last post by:
Hi all, I am fairly new to C#. so go easy on me :-) Anyhow, I have a class file that I have set up properties and a method. I am calling this class file directly from and aspx.cs file. So...
6
by: Lenn | last post by:
Hi, Could someone clarify my confusion regarding passing reference types to a method with ref keyword and explain when it's practical to use it. It's my understanding that in .NET reference...
1
by: John Miller | last post by:
I'm developing a form that captures patient information. In the form, I need the ability to add several insurance policies. The approach I have decided to take is to load the separate insurance...
3
by: Stephen Travis | last post by:
I'm trying to write a subroutine that will fill an array of some type with several objects of that type. The subroutine works fine if I directly reference the array but if I pass the array as an...
3
by: Winshent | last post by:
I want to pass optional arguments to build up varios strings, is this possible? look at arrTBL(1,3) in the code below: =========================================== Public Function...
7
by: Rik | last post by:
Hi, I have an Multithreaded application in VB.NET. I inherited a Sub Class and which define an Array variable of string in that Sub Class. Now I want to Carry that Sub Class Array back to...
8
by: amazon | last post by:
I have a following structure that I am using with array list: Private Structure arrayliststruct Public Name As String Public value As String Public type As String End Structure and following...
8
by: =?Utf-8?B?UmF2aQ==?= | last post by:
Hi, I'm trying to pass values of different data-types to a web-service. I thought it would be easier to box these values and pass them as a System.object parameter, like public void...
2
by: =?Utf-8?B?Y3Nz?= | last post by:
I am new to ASP.net webservice and have a quesiton. Is is possible to pass custom object to a web service (using VB 2005)? My custom object will look like this Public Class Myclass Public...
3
by: Christopher H | last post by:
I've been reading about how C# passes ArrayLists as reference and Structs as value, but I still can't get my program to work like I want it to. Simple example: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.