By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,673 Members | 1,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,673 IT Pros & Developers. It's quick & easy.

Displaying Contents of ArrayList

P: n/a
I have an ArrayList which stores x number of "Policy" objects, where x is
the number of rows returned from a earlier SQL query (therefore it is
changeable).

Each "Policy" has a few methods within it that returns values.

How do I display a row of information for each "Policy" (stored in the
ArrayList) in the browser?

Also, what is the best way of assigning values returned from object methods
to specfic fields in DataLists, DataGrids etc?
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I have never actually done this before, but from what I understand, you can
add databindings to the datagrid databindings collection. Each databinding
binds the value of a property in your Policy objects to a column in the
datagrid.

In order to do this, your collection must implement the IList interface,
which the ArrayList does.

"Beza" <be**@beza.com> wrote in message
news:e0**************@TK2MSFTNGP11.phx.gbl...
I have an ArrayList which stores x number of "Policy" objects, where x is
the number of rows returned from a earlier SQL query (therefore it is
changeable).

Each "Policy" has a few methods within it that returns values.

How do I display a row of information for each "Policy" (stored in the
ArrayList) in the browser?

Also, what is the best way of assigning values returned from object methods to specfic fields in DataLists, DataGrids etc?

Nov 13 '05 #2

P: n/a
Regarding the array list, try: (and this will be long-hand, there are
plenty of places to take short cuts, but I'm doing it long hand to
show you the steps)

object[] policies = ArrayListofPolicies.ToArray();
// hashed out - this might be ordered, not sure.
foreach( object o in policies ){
Policy p = (Policy)o;
string txt = p.Method1() + "\t";
txt += p.Method2();
txt += p.Method3();
txt += p.Method4();
Console.WriteLine( txt );
}

//or indexed in order:
for( int x=0; x<policies.Length; x++ ){
Policy p = (Policy)policies[x];
string txt = p.Method1();
// .......
Console.WriteLine( txt );
}

Again, this is sloppy long-hand, but I think you get the gist of it.

Also, if you wrote the Policy object and can change it, you might want
to expose the "pieces of information" as an array of values.

for( int x=0; x<policies.Length; x++ ){
Policy p = (Policy)policies[x];
string txt = "";
for( int y=0; y<p.Values.Length; y++ ){
txt += p.Values[x] + "\t";
}
Console.WriteLine( txt );
}

or with a class indexer:
for( int x=0; x<policies.Length; x++ ){
Policy p = (Policy)policies[x];
string txt = "";
for( int y=0; y<p.ValueCount; y++ ){
txt += p[x] + "\t";
}
Console.WriteLine( txt );
}

There are many options.

"Beza" <be**@beza.com> wrote in message news:<e0**************@TK2MSFTNGP11.phx.gbl>...
I have an ArrayList which stores x number of "Policy" objects, where x is
the number of rows returned from a earlier SQL query (therefore it is
changeable).

Each "Policy" has a few methods within it that returns values.

How do I display a row of information for each "Policy" (stored in the
ArrayList) in the browser?

Also, what is the best way of assigning values returned from object methods
to specfic fields in DataLists, DataGrids etc?

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.