Output a Grid (Table) from a Collection?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

Save I have a collection/arraylist, etc of 15, 20, 30 items. Does anyone
have some neat code to output it into an abitrary grid table (i.e. 3x3,
4x4, 6x6, etc)?

I know this is pretty trival to write - but I feel lazy today (plus I want
to see what others have come up with).

Thanks.
 
My suggestion is to not write your own code to do this, but to use
databinding (such as the DataList or DataGrid controls). This would be much
more efficient, and will make it easier for you to manipulate the look of
the output. If you are not familiar with databinding, don't let it scare
you. Once you've seen a few examples, you'll love it. A good book that I
would recommend if you aren't familiar with databinding is "ASP.NET
Unleashed" by Stephen Walther, the book pretty much increased my knowledge
of ASP.NET by ten-fold, and it gives plenty of examples, so you can see all
the code involved.
 
My suggestion is to not write your own code to do this, but to use
databinding (such as the DataList or DataGrid controls).

If I use a datagrid, don't I have to predefine the grid to be x columns
wide?

Same with a datalist?
 
I believe you do have to predefine it for DataGrids (I have never used
DataGrids because I found DataLists simpler, so I could be wrong about
that), but for DataLists you do not need to. You basically create what is
called a Template. A Template is basically the same as other design code in
ASP.NET, except the attributes that you want data entered for from a
DataTable, Collection, SortedList, Array, or other collection type are
entered using a special syntax rather than static text. Do a search for some
examples, you shouldn't have much trouble with it, and trust me, it will
save you a lot of time. Good Luck!
 
I believe you do have to predefine it for DataGrids (I have never used
DataGrids because I found DataLists simpler, so I could be wrong about
that), but for DataLists you do not need to. You basically create what
is called a Template. A Template is basically the same as other design
code in ASP.NET, except the attributes that you want data entered for
from a DataTable, Collection, SortedList, Array, or other collection
type are entered using a special syntax rather than static text. Do a
search for some examples, you shouldn't have much trouble with it, and
trust me, it will save you a lot of time. Good Luck!



Funny - I never used the DataList because I liked the DataGrid's complexity
; ) I'll take a look at the DataList. My custom objects are all datalist
compatible anyways.

Thanks!
 
I believe you do have to predefine it for DataGrids (I have never used
DataGrids because I found DataLists simpler, so I could be wrong about
that), but for DataLists you do not need to.

I used the datalist to output a multi-column datalist. Works great! Very
simple to do too : )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top