473,396 Members | 2,115 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,396 software developers and data experts.

Sort() an arraylist in a different function that I initialised it!

Expand|Select|Wrap|Line Numbers
  1. public partial class images_Exercise2 : System.Web.UI.Page
  2. {
  3.     ArrayList numbers = new ArrayList();
  4.  
  5.     protected void Page_Load(object sender, EventArgs e)
  6.     {
  7.  
  8.     }
  9.  
  10.     protected void Button1_Click(object sender, EventArgs e)
  11.     {
  12.  
  13.         int num = 0;
  14.         Random RandomClass = new Random();
  15.         numbers.Clear();
  16.  
  17.         for (int i = 0; i < 6; i++)
  18.         {
  19.             num = RandomClass.Next(1, 49);
  20.  
  21.             while (!numbers.Contains(num))
  22.             {
  23.                 numbers.Add(num);
  24.             }
  25.         }
  26.  
  27.  
  28.         Label1.Text = numbers[0].ToString();
  29.         Label2.Text = numbers[1].ToString();
  30.         Label3.Text = numbers[2].ToString();
  31.         Label4.Text = numbers[3].ToString();
  32.         Label5.Text = numbers[4].ToString();
  33.         Label6.Text = numbers[5].ToString();
  34.  
  35.  
  36.  
  37.  
  38.     protected void Button2_Click(object sender, EventArgs e)
  39.     {
  40.         numbers.Sort();
  41.         Label1.Text = numbers[0].ToString();
  42.         Label2.Text = numbers[1].ToString();
  43.         Label3.Text = numbers[2].ToString();
  44.         Label4.Text = numbers[3].ToString();
  45.         Label5.Text = numbers[4].ToString();
  46.         Label6.Text = numbers[5].ToString();
  47.  
  48.  
  49.     }
  50. }
The problem is When I click on the Button_2 the arraylist lose all the data so i empty so I can't sort it! I couldn't find a way to keep the data in the arraylist! Can you help me?
Mar 31 '14 #1
0 1019

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Rob | last post by:
Hi I have a dataset that is ordered by the primary key, but when I view it in a dataview with the sort propery filled in with the primary key, the order is different. The data that seems to cause...
4
by: Paul Reddin | last post by:
Hi, Anyone got a nice solution (Single query) for the following Given the following table C1 C2 C3 Y A 6 Y B 5 Y C 4
2
by: Paul M | last post by:
Hi, This is on an AS/400 which can be a little strange but I think the basic question is portable. I have a (non-C) program that needs to make series of calls to some C programs/functions....
0
by: dhnriverside | last post by:
Hi peeps, I had a function working fine for retrieving a list of users from Active Directory. However, client wants it sorted alphabetically. So I added Sort option to my searcher, and now the...
3
by: christophe.verne | last post by:
Hi all, It's the first time I'm using groups so i hope I am posting on the good group. I''m not familiar with callback and function pointer and here is what I'd like to do: typedef struct...
4
by: M Harvey | last post by:
I have an arraylist that contains datetime values. What is the best way to sort this arraylist by date ascending? Thanks, Matt
2
by: csgraham74 | last post by:
Hi Guys, Just wondering if someone could help me with an arraylist issue. I have an array of integers Arraylist 4 , 2, 11, 2, 21, 3 ,15 , 30 i want the arraylist to now be sorted...
6
by: Kiran | last post by:
Hi all, What I am trying to do is to pass a pointer to the first element of an array to a function, modify it in that function, and then print out the values of the array (which has been modified...
2
by: kaushal | last post by:
i am trying to sort the strings without the functions ..but i can't bcz i can't trace out the javascript program...so need ur help..
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...

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.