shopping cart binding to datagrid

M

mazdotnet

Hi,

I'm wondering if there is a way to bind to datagrid or a gridview the
items in an arraylist. These items all have vars such as price,
qty..etc? (besides putting in a datagrid or datatable first).

ex.
ArrayList alShoppingCart = shoppingCart.GetCurrentItems;
alShoppingCart contains an array list of Item objects.

Thanks
Maz.
 
F

Flinky Wisty Pomm

You can bind to an ArrayList because its an IEnumerable. Or am I not
understanding?
 
M

mazdotnet

Flinky said:
You can bind to an ArrayList because its an IEnumerable. Or am I not
understanding?

You can but my arraylist contains objects of the other type (items)
since it's a shopping cart. Each item has public fields (Id, Price,
Qty...etc). How do you tell my gridview to bind to those fields?

Thanks
MA
 
F

Flinky Wisty Pomm

Like this:
<asp:GridView runat="server">
<BoundField HeaderText="Item Code" DataField="Id" />
<BoundField HeaderText="Price" DataField="Price" HtmlEncode="false"
DataFormatString="{0:c}" />
<BoundField HeaderText="Quantity" DataField="Qty" />
</asp:GridView>

Note the HtmlEncode attribute on the price field - if you don't include
it, your data format string won't work because the value of Price is
treated as a string and not a numeric value.

HTH

-- flink
 

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

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top