all groups > asp.net datagrid control > september 2004 >
You're in the

asp.net datagrid control

group:

Populating a datagrid control ...


Populating a datagrid control ... Prime
9/30/2004 12:19:22 PM
asp.net datagrid control: Hi All ...

I'm writing a small shopping cart app (uni assignment) and need to list all
the books that a user selects.

I have created a "BookBasket" object that contains among other things an
arraylist of the user selected books.
The "book" object contains isbn,title price and quantity information.

I'd like to display the contents of the BookBasket in a datagrid control.

I assume that to start with I'd have to iterate through the basket to
identify each books information, but then how do I populate the datagrid
manually?

It seems from what I've read,that it is easier to populate a datagrid from a
datasource, but I don't know how that would relate to what I'm doing.

any clues or links to examples would be much appreciated.

Thanks in advance

Prime.


Re: Populating a datagrid control ... Ken Cox [Microsoft MVP]
9/30/2004 10:56:59 PM
You can bind a datagrid to a simple array list. Is that what you meant?

Dim values As ArrayList = New ArrayList
values.Add("IN")
values.Add("KS")
values.Add("MD")
values.Add("MI")
values.Add("OR")
values.Add("TN")
DataGrid1.DataSource = values
DataGrid1.DataBind()

[quoted text, click to view]
Re: Populating a datagrid control ... Prime
10/1/2004 2:45:58 PM
Hi Ken,

Thanks for the reply.

The array list contains "SelectedBook" objects which are instances of class
Book ... which are not simple data types.
eg:
public class Book
private strISBN as string
private strTitle as string
Private sngPrice as single
....

'Poperty procedures follow...
....
end class

Public class BookBasket
private arrSelectedBooks as arraylist = new arraylist
....
' property procedures etc follow ...

end class

I don't think a datagrid would be able to display the elements of the book
object without some special coding

Jared has pointed me to a good sample on gotdotnet which I am studying ... I
suspect it will do the job for me.

Thanks again for the reply.

Prime.


[quoted text, click to view]

AddThis Social Bookmark Button