473,421 Members | 1,602 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,421 software developers and data experts.

Arraylist issue

Hi all,

I have...

using System.Collections;
namespace MyApp.Templates
{
public class MyPage : System.Web.UI.Page
{
ArrayList MyArray = new ArrayList();
int MyPointer;

private void FillArray_Click(object sender,
EventArgs e)
{
foreach (DataGridItem i in MyGrid.Items)
{
CheckBox cbSelectRows = (CheckBox)
i.FindControl("cbSelect");
if (cbSelectRows.Checked)
{
MyArray.Add(((Label) i.FindControl
("DFESLabel")).Text.ToString());
Trace.Warn(((Label) i.FindControl
("DFESLabel")).Text.ToString());
}
}
MyPointer = 0;
Response.Write (MyArray[MyPointer].ToString
());
}
private void NextButton_Click(object sender,
EventArgs e)
{
Trace.Warn("ArrayCount",
MyArray.Count.ToString());
MyPointer ++;
Trace.Warn(MyPointer.ToString());
Response.Write(MyArray MyPointer].ToString());
}

}
}
Notice my arraylist is defined outside of any functions
or events. This is to make it useable in any of the
functions.

When I do FillArray_Click, the array fills up correctly.

If however, once I have filled the arraylist, then click
NextButton, the arraylist appears to be empty. How come?
I have already filled it, it is a global arraylist, so to
me, it should remain filled.

This is C# in ASP.NET.

Thanks for any help.
Regards,
Dave Colliver.
http://www.BlackpoolFOCUS.com

Nov 19 '05 #1
7 1770
It wrote a lot of times. :))

foreach (DataGridItem i in MyGrid.Items)
{
i.Cell[CellNumber].FindControl("ControlID"); // It returns your
control
i.Cell[CellNumber].Controls[0]; // It returns your control too.
}
Any Item has cells. You have to defive a cell number. adn just then you can
do the serch of the control.

Mike

"Dave" <da***@revilloc.remove.this.bit.com> wrote in message
news:09****************************@phx.gbl...
Hi all,

I have...

using System.Collections;
namespace MyApp.Templates
{
public class MyPage : System.Web.UI.Page
{
ArrayList MyArray = new ArrayList();
int MyPointer;

private void FillArray_Click(object sender,
EventArgs e)
{
foreach (DataGridItem i in MyGrid.Items)
{
CheckBox cbSelectRows = (CheckBox)
i.FindControl("cbSelect");
if (cbSelectRows.Checked)
{
MyArray.Add(((Label) i.FindControl
("DFESLabel")).Text.ToString());
Trace.Warn(((Label) i.FindControl
("DFESLabel")).Text.ToString());
}
}
MyPointer = 0;
Response.Write (MyArray[MyPointer].ToString
());
}
private void NextButton_Click(object sender,
EventArgs e)
{
Trace.Warn("ArrayCount",
MyArray.Count.ToString());
MyPointer ++;
Trace.Warn(MyPointer.ToString());
Response.Write(MyArray MyPointer].ToString());
}

}
}
Notice my arraylist is defined outside of any functions
or events. This is to make it useable in any of the
functions.

When I do FillArray_Click, the array fills up correctly.

If however, once I have filled the arraylist, then click
NextButton, the arraylist appears to be empty. How come?
I have already filled it, it is a global arraylist, so to
me, it should remain filled.

This is C# in ASP.NET.

Thanks for any help.
Regards,
Dave Colliver.
http://www.BlackpoolFOCUS.com

Nov 19 '05 #2
Hi,

In the foreach, I am adding the item value from a label
in a datagrid into the arraylist. This appears to work.
However, when I next try to read the arraylist, there is
nothing in it.

I have just tried reading direct form the grid (without a
foreach) and it sort of works...

e.g.
Trace.Warn("FromDG", ((Label) MyListGrid.Items
[MyPointer].FindControl("DFESLabel")).Text.ToString());

However, I have a column of checkboxes. I check these as
items I want to cycle through. In my original foreach, I
am reading if the checkbox is checked, then transfer the
row item into the arraylist. This gives me finer (and I
would assume faster overall) control as I don't have to
go through a DG that is 400 lines long for every press of
the next/previous buttons.

As yet, I don't know how to break out of a foreach loop
(.NET newbie).

I was hoping not to do a foreach in every button click,
just index the position of an arraylist.

Advice still appreciated.

Best regards,
Dave Colliver.
http://www.BakewellFOCUS.com

-----Original Message-----
It wrote a lot of times. :))

foreach (DataGridItem i in MyGrid.Items)
{
i.Cell[CellNumber].FindControl("ControlID"); // It returns yourcontrol
i.Cell[CellNumber].Controls[0]; // It returns your control too.}
Any Item has cells. You have to defive a cell number. adn just then you cando the serch of the control.

Mike

"Dave" <da***@revilloc.remove.this.bit.com> wrote in messagenews:09****************************@phx.gbl...
Hi all,

I have...

using System.Collections;
namespace MyApp.Templates
{
public class MyPage : System.Web.UI.Page
{
ArrayList MyArray = new ArrayList();
int MyPointer;

private void FillArray_Click(object sender,
EventArgs e)
{
foreach (DataGridItem i in MyGrid.Items)
{
CheckBox cbSelectRows = (CheckBox)
i.FindControl("cbSelect");
if (cbSelectRows.Checked)
{
MyArray.Add(((Label) i.FindControl
("DFESLabel")).Text.ToString());
Trace.Warn(((Label) i.FindControl
("DFESLabel")).Text.ToString());
}
}
MyPointer = 0;
Response.Write (MyArray[MyPointer].ToString
());
}
private void NextButton_Click(object sender,
EventArgs e)
{
Trace.Warn("ArrayCount",
MyArray.Count.ToString());
MyPointer ++;
Trace.Warn(MyPointer.ToString());
Response.Write(MyArray MyPointer].ToString ()); }

}
}
Notice my arraylist is defined outside of any functions
or events. This is to make it useable in any of the
functions.

When I do FillArray_Click, the array fills up correctly.
If however, once I have filled the arraylist, then click NextButton, the arraylist appears to be empty. How come? I have already filled it, it is a global arraylist, so to me, it should remain filled.

This is C# in ASP.NET.

Thanks for any help.
Regards,
Dave Colliver.
http://www.BlackpoolFOCUS.com

.

Nov 19 '05 #3
Hi,

When you click the "Next" button, the post back occurs, and hence the
arraylist is again filled with empty. Check for PostBack event of Page, and
fill the arraylist accordingly.

Prakash.C

"Dave" wrote:
Hi all,

I have...

using System.Collections;
namespace MyApp.Templates
{
public class MyPage : System.Web.UI.Page
{
ArrayList MyArray = new ArrayList();
int MyPointer;

private void FillArray_Click(object sender,
EventArgs e)
{
foreach (DataGridItem i in MyGrid.Items)
{
CheckBox cbSelectRows = (CheckBox)
i.FindControl("cbSelect");
if (cbSelectRows.Checked)
{
MyArray.Add(((Label) i.FindControl
("DFESLabel")).Text.ToString());
Trace.Warn(((Label) i.FindControl
("DFESLabel")).Text.ToString());
}
}
MyPointer = 0;
Response.Write (MyArray[MyPointer].ToString
());
}
private void NextButton_Click(object sender,
EventArgs e)
{
Trace.Warn("ArrayCount",
MyArray.Count.ToString());
MyPointer ++;
Trace.Warn(MyPointer.ToString());
Response.Write(MyArray MyPointer].ToString());
}

}
}
Notice my arraylist is defined outside of any functions
or events. This is to make it useable in any of the
functions.

When I do FillArray_Click, the array fills up correctly.

If however, once I have filled the arraylist, then click
NextButton, the arraylist appears to be empty. How come?
I have already filled it, it is a global arraylist, so to
me, it should remain filled.

This is C# in ASP.NET.

Thanks for any help.
Regards,
Dave Colliver.
http://www.BlackpoolFOCUS.com

Nov 19 '05 #4
Hi,

I thought the idea of making the arraylist global would
negate the issue of postback and make it survivable. I am
not filling the arraylist on the page_load, I am using an
onclick event to fill the arraylist, then another onclick
to index the position and read the arraylist.

How else can I make the arraylist survivable?

Thanks.
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
-----Original Message-----
Hi,

When you click the "Next" button, the post back occurs, and hence thearraylist is again filled with empty. Check for PostBack event of Page, andfill the arraylist accordingly.

Prakash.C

"Dave" wrote:
Hi all,

I have...

using System.Collections;
namespace MyApp.Templates
{
public class MyPage : System.Web.UI.Page
{
ArrayList MyArray = new ArrayList();
int MyPointer;

private void FillArray_Click(object sender,
EventArgs e)
{
foreach (DataGridItem i in MyGrid.Items)
{
CheckBox cbSelectRows = (CheckBox)
i.FindControl("cbSelect");
if (cbSelectRows.Checked)
{
MyArray.Add(((Label) i.FindControl
("DFESLabel")).Text.ToString());
Trace.Warn(((Label) i.FindControl
("DFESLabel")).Text.ToString());
}
}
MyPointer = 0;
Response.Write (MyArray[MyPointer].ToString
());
}
private void NextButton_Click(object sender,
EventArgs e)
{
Trace.Warn("ArrayCount",
MyArray.Count.ToString());
MyPointer ++;
Trace.Warn(MyPointer.ToString());
Response.Write(MyArray MyPointer].ToString ()); }

}
}
Notice my arraylist is defined outside of any functions or events. This is to make it useable in any of the
functions.

When I do FillArray_Click, the array fills up correctly.
If however, once I have filled the arraylist, then click NextButton, the arraylist appears to be empty. How come? I have already filled it, it is a global arraylist, so to me, it should remain filled.

This is C# in ASP.NET.

Thanks for any help.
Regards,
Dave Colliver.
http://www.BlackpoolFOCUS.com

.

Nov 19 '05 #5
Hi Dave,
As you know the HTTP protocol is stateless protocol, so with each request we
need to build all required objects and populate variable from scratch. Even
if your variables or objects are global they will not be available in next
postback request.

To pass this data from one request to next request we need to store it
somewhere. There are few possible ways to do it. Depending on your
requirements you can use the most appropriate method.

1. Use Session to store your data.
2. Use Cache to store in application cache.
3. Make it a static variable of global application object.
4. Serialize the data and store it either in viewstate or file system, and
then deserialize in next request.

Hope it will help.

--
Cheers,
Rahul Anand

"Dave" wrote:
Hi,

I thought the idea of making the arraylist global would
negate the issue of postback and make it survivable. I am
not filling the arraylist on the page_load, I am using an
onclick event to fill the arraylist, then another onclick
to index the position and read the arraylist.

How else can I make the arraylist survivable?

Thanks.
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
-----Original Message-----
Hi,

When you click the "Next" button, the post back

occurs, and hence the
arraylist is again filled with empty. Check for PostBack

event of Page, and
fill the arraylist accordingly.

Prakash.C

"Dave" wrote:
Hi all,

I have...

using System.Collections;
namespace MyApp.Templates
{
public class MyPage : System.Web.UI.Page
{
ArrayList MyArray = new ArrayList();
int MyPointer;

private void FillArray_Click(object sender,
EventArgs e)
{
foreach (DataGridItem i in MyGrid.Items)
{
CheckBox cbSelectRows = (CheckBox)
i.FindControl("cbSelect");
if (cbSelectRows.Checked)
{
MyArray.Add(((Label) i.FindControl
("DFESLabel")).Text.ToString());
Trace.Warn(((Label) i.FindControl
("DFESLabel")).Text.ToString());
}
}
MyPointer = 0;
Response.Write (MyArray[MyPointer].ToString
());
}
private void NextButton_Click(object sender,
EventArgs e)
{
Trace.Warn("ArrayCount",
MyArray.Count.ToString());
MyPointer ++;
Trace.Warn(MyPointer.ToString());
Response.Write(MyArray MyPointer].ToString ()); }

}
}
Notice my arraylist is defined outside of any functions or events. This is to make it useable in any of the
functions.

When I do FillArray_Click, the array fills up correctly.
If however, once I have filled the arraylist, then click NextButton, the arraylist appears to be empty. How come? I have already filled it, it is a global arraylist, so to me, it should remain filled.

This is C# in ASP.NET.

Thanks for any help.
Regards,
Dave Colliver.
http://www.BlackpoolFOCUS.com

.

Nov 19 '05 #6
Hi,

Yes, I understand it is a stateless protocol (I have
extensive classic asp), but I would have thought that a
global variable would have held itself, probably using
the viewstate. Perhaps not. I thought the idea of
webforms was to make it work like winforms, in that
setting a value would hold between pages.

Perhaps I should make an invisible datagrid (or
datalist), populate it with the arraylist, then read it
back (as grids appear to hold state)

Cheers.
Dave.
http://www.NorthamptonFOCUS.com
-----Original Message-----
Hi Dave,
As you know the HTTP protocol is stateless protocol, so with each request weneed to build all required objects and populate variable from scratch. Evenif your variables or objects are global they will not be available in nextpostback request.

To pass this data from one request to next request we need to store itsomewhere. There are few possible ways to do it. Depending on yourrequirements you can use the most appropriate method.

1. Use Session to store your data.
2. Use Cache to store in application cache.
3. Make it a static variable of global application object.4. Serialize the data and store it either in viewstate or file system, andthen deserialize in next request.

Hope it will help.

--
Cheers,
Rahul Anand

"Dave" wrote:
Hi,

I thought the idea of making the arraylist global would negate the issue of postback and make it survivable. I am not filling the arraylist on the page_load, I am using an onclick event to fill the arraylist, then another onclick to index the position and read the arraylist.

How else can I make the arraylist survivable?

Thanks.
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
>-----Original Message-----
>Hi,
>
> When you click the "Next" button, the post back

occurs, and hence the
>arraylist is again filled with empty. Check for PostBack
event of Page, and
>fill the arraylist accordingly.
>
>Prakash.C
>
>"Dave" wrote:
>
>> Hi all,
>>
>> I have...
>>
>> using System.Collections;
>> namespace MyApp.Templates
>> {
>> public class MyPage : System.Web.UI.Page
>> {
>> ArrayList MyArray = new ArrayList();
>> int MyPointer;
>>
>> private void FillArray_Click(object sender,
>> EventArgs e)
>> {
>> foreach (DataGridItem i in MyGrid.Items)
>> {
>> CheckBox cbSelectRows = (CheckBox)
>> i.FindControl("cbSelect");
>> if (cbSelectRows.Checked)
>> {
>> MyArray.Add(((Label)
i.FindControl >> ("DFESLabel")).Text.ToString());
>> Trace.Warn(((Label) i.FindControl >> ("DFESLabel")).Text.ToString());
>> }
>> }
>> MyPointer = 0;
>> Response.Write (MyArray [MyPointer].ToString >> ());
>> }
>>
>>
>> private void NextButton_Click(object sender, >> EventArgs e)
>> {
>> Trace.Warn("ArrayCount",
>> MyArray.Count.ToString());
>> MyPointer ++;
>> Trace.Warn(MyPointer.ToString());
>> Response.Write(MyArray

MyPointer].ToString ());
>> }
>>
>> }
>> }
>>
>>
>> Notice my arraylist is defined outside of any

functions
>> or events. This is to make it useable in any of the
>> functions.
>>
>> When I do FillArray_Click, the array fills up

correctly.
>>
>> If however, once I have filled the arraylist, then

click
>> NextButton, the arraylist appears to be empty. How

come?
>> I have already filled it, it is a global arraylist,
so to
>> me, it should remain filled.
>>
>> This is C# in ASP.NET.
>>
>> Thanks for any help.
>> Regards,
>> Dave Colliver.
>> http://www.BlackpoolFOCUS.com
>>
>>
>.
>

.

Nov 19 '05 #7
Hi,

Storing it in ViewState will be a good choice. The arraylist will be sent
to client and then returned back. It will cause extra data to be sent to
client. The other options are Cache, Session and Application.

To add to view state, the command is ViewState("<variablename>") =
<arraylist>

Hope it helps

Prakash.C

"Dave" wrote:
Hi,

Yes, I understand it is a stateless protocol (I have
extensive classic asp), but I would have thought that a
global variable would have held itself, probably using
the viewstate. Perhaps not. I thought the idea of
webforms was to make it work like winforms, in that
setting a value would hold between pages.

Perhaps I should make an invisible datagrid (or
datalist), populate it with the arraylist, then read it
back (as grids appear to hold state)

Cheers.
Dave.
http://www.NorthamptonFOCUS.com
-----Original Message-----
Hi Dave,
As you know the HTTP protocol is stateless protocol, so

with each request we
need to build all required objects and populate variable

from scratch. Even
if your variables or objects are global they will not be

available in next
postback request.

To pass this data from one request to next request we

need to store it
somewhere. There are few possible ways to do it.

Depending on your
requirements you can use the most appropriate method.

1. Use Session to store your data.
2. Use Cache to store in application cache.
3. Make it a static variable of global application

object.
4. Serialize the data and store it either in

viewstate or file system, and
then deserialize in next request.

Hope it will help.

--
Cheers,
Rahul Anand

"Dave" wrote:
Hi,

I thought the idea of making the arraylist global would negate the issue of postback and make it survivable. I am not filling the arraylist on the page_load, I am using an onclick event to fill the arraylist, then another onclick to index the position and read the arraylist.

How else can I make the arraylist survivable?

Thanks.
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com

>-----Original Message-----
>Hi,
>
> When you click the "Next" button, the post back
occurs, and hence the
>arraylist is again filled with empty. Check for PostBack event of Page, and
>fill the arraylist accordingly.
>
>Prakash.C
>
>"Dave" wrote:
>
>> Hi all,
>>
>> I have...
>>
>> using System.Collections;
>> namespace MyApp.Templates
>> {
>> public class MyPage : System.Web.UI.Page
>> {
>> ArrayList MyArray = new ArrayList();
>> int MyPointer;
>>
>> private void FillArray_Click(object sender,
>> EventArgs e)
>> {
>> foreach (DataGridItem i in MyGrid.Items)
>> {
>> CheckBox cbSelectRows = (CheckBox)
>> i.FindControl("cbSelect");
>> if (cbSelectRows.Checked)
>> {
>> MyArray.Add(((Label) i.FindControl >> ("DFESLabel")).Text.ToString());
>> Trace.Warn(((Label) i.FindControl >> ("DFESLabel")).Text.ToString());
>> }
>> }
>> MyPointer = 0;
>> Response.Write (MyArray [MyPointer].ToString >> ());
>> }
>>
>>
>> private void NextButton_Click(object sender, >> EventArgs e)
>> {
>> Trace.Warn("ArrayCount",
>> MyArray.Count.ToString());
>> MyPointer ++;
>> Trace.Warn(MyPointer.ToString());
>> Response.Write(MyArray MyPointer].ToString ());
>> }
>>
>> }
>> }
>>
>>
>> Notice my arraylist is defined outside of any
functions
>> or events. This is to make it useable in any of the
>> functions.
>>
>> When I do FillArray_Click, the array fills up
correctly.
>>
>> If however, once I have filled the arraylist, then
click
>> NextButton, the arraylist appears to be empty. How
come?
>> I have already filled it, it is a global arraylist, so to
>> me, it should remain filled.
>>
>> This is C# in ASP.NET.
>>
>> Thanks for any help.
>> Regards,
>> Dave Colliver.
>> http://www.BlackpoolFOCUS.com
>>
>>
>.
>

.

Nov 19 '05 #8

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

Similar topics

7
by: Alex Ting | last post by:
Hi Everybody, I have an issue about deleting an object from an arrayList. I've bounded a datagrid using this code where it will first run through all of the code in loadQuestions() and bind a...
10
by: Eric | last post by:
I'm looking at this page in the MSDN right here: ms-help://MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfsystemcollectionsarraylist classsynchronizedtopic2.htm (or online here:...
1
by: sd | last post by:
QUESTION: How can my ASP page - which uses language="VBScript" - pass a "System.Collections.ArrayList" object - as a parameter - to a C# method in the middle-tier ??? ----- Is it possible at...
4
by: Peter | last post by:
I run into this situation all the time and I'm wondering what is the most efficient way to handle this issue: I'll be pulling data out of a data source and want to load the data into an array so...
48
by: Alex Chudnovsky | last post by:
I have come across with what appears to be a significant performance bug in ..NET 2.0 ArrayList.Sort method when compared with Array.Sort on the same data. Same data on the same CPU gets sorted a...
6
by: Vinit | last post by:
Hi I am passing an arraylist to a c#/.net webmethod from a perl client using soap:lite. The trace shows the elements in the xml request. The arraylist input in the webmethod however does not...
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: ...
1
tifoso
by: tifoso | last post by:
I searched here and only found somebody with a round-robin arraylist issue here but what they suggest I tried already and it doesn't work for me I hope somebody can shed some light Scenario: I'm...
8
by: Guy | last post by:
Is there a better way to search identical elements in a sorted array list than the following: iIndex = Array.BinarySearch( m_Array, 0, m_Array.Count, aSearchedObject ); aFoundObject= m_Array;...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
1
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.