Creating dynamic array,adding stringsinto the array and retrieving string


I want to create a dynamic array which will contain string......then dynamically I will add strings to the array....At the end how i will retrieve strings from that array......

for example....i have a textbox, a button named add, and a button named show...... 1st i will write some string in the textbox....whene i click on the ADD button.the string wriiten in the textbox will be added to the array.....again i will write another string in textbox...again click the ADD button....that will be added to the array.................

so at the end when i click on the SHOW button, I want to see all the strings which i have entered.........

6/20/2007 4:42:00 AM 3977 articles. 0 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 43

Code behind should be as : 

Sub AddButton_Click(ByVal sender As Object,ByVal e As System.EventArgs)

Dim sMyArray As String= New String()


End Sub


Sub ShowButton_Click(ByVal sender As Object,ByVal e As System.EventArgs)

Dim Value As String

For Each value As String In sMyArray



End Sub

6/20/2007 5:08:29 AM

for dynamic allocation of a list of objects you need to use either generics or ArrayList 

if we used generics plus session to maintain the value between postbacks the code beside would be something like:



using System.Collections.Generic;
using System;
using System.Text;
public partial class _Default : System.Web.UI.Page
private List<string> ResultArray
if (Session["resultArray"] == null)
Session["resultArray"] = new List<string>();
return (List<string>)Session["resultArray"];

protected void btnAdd_Click(object sender, EventArgs e)
txtNewText.Text = string.Empty;
protected void btnShow_Click(object sender, EventArgs e)
StringBuilder sb = new StringBuilder();
foreach (string s in ResultArray)
sb.Append("<br />" + s);
lblResultingText.Text = sb.ToString();

 of course I don't recommend using session between post backs to the same page, rather, I recommend adding the strings to a comma separated string and storing it in the view state.

<%= Eyad.Salamin %>

<aspForums:DontForget>Don't forget to click on Mark as answer on the post that helped you.

This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped. </aspForums:DontForget>
6/20/2007 5:15:53 AM

Similar Artilces:

How to create array of strings dynamically in
Hi there I need to read the menu items from table and wants to create arrays of menus dynamically. Like dim Expertise() as string = {"ONE", "TWO", "THREE"} ONE, TWO and THREE will be comming from the database. Pls assist me the same for my convenient. Regards Raj_________________________________________________________________________...

Arrays, Arrays, Arrays
I mainly come from a JScript classic ASP background and I'm liking both and Now I have to say... "What's happened to arrays?" They used to be so flexible and easy to use. Here are my quick questions... Am I allowed to create an array with a non specified length so that I can add to it? If not then how can I modify an array's length? Can I create an array with a named index eg myArray["apple"] = "tasty"; or is the hash table the equivalent for this now? The classic array methods and properties like pop(), push(), length etc... are ...

Trying to dynamically create arrays, getting can't use string as ARRAY ref
Greets. I have a 'config file' that contains a group name (alphanumeric) and machine name/numbers separated by whitespace. Each group is on it's own line. The file looks like this: prod01 456 345 234 prod02 789 517 325 ....etc, etc, etc... What I am attempting to do is: Put the file contents into an array Pull the first entry off the array Add the name of the array to a 'master array' list of the machine groups Then create another array, which would be referenced by the group name, and contains the machines associated with the group. Here is the code...

Adding Parameters dynamically for search string from string array
I am building a search string dynamically. One of the items for the string is stored in a sting array in a ViewState object. I want to be able to retrieve the values from the ViewState object and create the string. I have part of the code here and need help in completing the portion indicated. Main problem is how do I build the string for the parameter values. Thanks in advance. OracleCommand cmd = conn.create(); if ( ViewState ["stringArray"]!=null ) {String [] stringArray=ViewState ["stringArray"];if ( stringArray.Length>0 ) { if ( stringArray.Length==1 ) ... headache
Hi Il try to make this as straight forward as I can. I have an app that users can use to predict sporting results.After each game points are calulated for each user depending on how their prediction matched the results.I have done this nice and simply for each individual user by joining two tables (from SQL), running some functions in codebehind and displaying the results in a gridview.this ofcourse is only for the active "logged in" user. Aswell as this I would also like to create a list of the top 10 predicters....

problem with dynamic array of dynamic array
var a:array of array of integer; begin setlength(a,2); setlength(a[0],1); setlength(a[1],2); a[0,0]:=1; //it is ok a[0,1]:=2; //it is not ok in my understanding a[0,1]:=2 is not ok because a[0] has only one element as i declared setlength(a[0],1) so i dont understand why this code exemple is compiled and run just fine ? > {quote:title=Yossi Rozenberg wrote:}{quote} > in my understanding a[0,1]:=2 is not ok because a[0] has only one element as i declared setlength(a[0],1) so i dont understand why this code exemple is compiled and run just fine ? By default, acces...

Using array of array of strings v List<List<string>> w/ web services
I am having some trouble calling a web service method that has a List <List string>> and passing a javascript Array (rank = 2).  My solution was to use object[] as an arg. Not sure why List <string> works great with web methods but List<List <string>> method never gets called until I switch to using object[].  Not a big deal, makes my code a little uglier. Thanks. AORegards,Alex Osipov Thanks for reporting this issue, this turns out to be a bug in the current implementation, and will be fixed in a future CTP... Thanks for quick reply! &n...

Concatenating arrays from arrays of arrays
Hello - I am trying to accumulate items in a flat list (array) by concatenating on to it the scalars contained in arrays which in turn are contained in arrays. The data is to be read in from a file rather than existing as literals in my code. Everything I try either crashes the computer or gives me an array of arrays instead of a flat list. I have been programming in Unicon which has a concatenate operator, but Perl makes very heavy weather of nested list management. Should I switch to Lisp, or is there a way of doing what I want to do in Perl? Regards _John Sampson_ On...

referring to an array in an array of arrays
How can I get at an array in an array of arrays? I'm creating the arrays using: $fComments[$i++] = [ @comments ]; Now I want to get back what I put in: print "$fComments[0]\n"; but this prints ARRAY(0x107671f0). How do I follow that pointer? (I really think we need a pre-beginners list... =) TIA. - B You can try something like this: print "@{$fComments[0]}\n"; Which will attempt to dereference the array at $fComments[0]. -----Original Message----- From: Bryan R Harris [] Sent: Tue...

How to unshift to an array in an array of arrays?
How to unshift to an array in an array of arrays? > -----Original Message----- > From: Angerstein [] > Sent: Wednesday, August 28, 2002 6:12 AM > To: > Subject: How to unshift to an array in an array of arrays? > > > How to unshift to an array in an array of arrays? $ perl -d -e 1 ..... DB<1> @aoa = ([qw(foo bar baz)]) << create array of arrays DB<2> x @aoa 0 ARRAY(0x80f82dc) 0 'foo' 1 'bar' 2 'baz' DB<3> unshift @{$aoa[0]}, 'qu...

Array of arrays
Hi I'm trying to return from a web service a array of arrays, one of the arrays is a array of objects, which I tested separately and it's working fine, and another array of integer and another of strings. When I run the web service I got this:You must implement a default accessor on System.Array because it inherits from ICollectionDefault accessor what that means? Thank you very much.  As Heinlein said "specialization is for insects" explore beyond the universe. Could you pls post the relevant code ? hi rushan thank you for the reply the code is here:  ...

Array of Array.
How is possible to declare a DYNAMIC array of array ? I need something like a dynamic hash table whose pages grow up dynamically too (each one can have different number of elements). In other words, a matrix that can be dynamic in both dimension. example: [1,2,3...] [3,4..] [5] [6,7,8,9...] [.] .. .. .. Have you considered using a DataStore? -- <hopethishelps/> Roy Kiesler [TeamSybase] SDN CodeXchange -- "Marco Meoni - News" <> wrote in message news:401ba036$1@forums-2-dub... > How ...

MOVED: problem with dynamic array of dynamic array
Moved to: embarcadero.public.delphi.language.delphi.general or: -- Rudy Velthuis Rudin's Law: In a crisis that forces a choice to be made among alternative courses of action, people tend to choose the worst possible course. ...

[@array] and \@array
Given the case, my @array = (1,2,3,4); my $var1 = [@array]; my $var2 = \@array; What's the difference between $var1 and $var2? Are they all refered to @array? Thanks guys. On 3/22/07, Jm lists <> wrote: > Given the case, > > my @array = (1,2,3,4); > my $var1 = [@array]; > my $var2 = \@array; > > What's the difference between $var1 and $var2? > Are they all refered to @array? > Thanks guys. $var2 is a reference to @array. $var1 is a reference to new array. Observe #!/usr/bin/perl use strict; use war...

Web resources about - Creating dynamic array,adding stringsinto the array and retrieving string -

V Plotter Design
A V plotter is a minimalistic design which uses a pair of steppers, somestring, and a pen head to create a plotter. These are sometimes made ...

Resources last updated: 12/24/2015 12:24:18 PM