shopping cart binding to datagrid  
Author Message
mazdotnet





PostPosted: 2006-5-13 3:53:01 Top

dotnet-framework-aspnet, shopping cart binding to datagrid 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.

 
mazdotnet





PostPosted: 2006-5-15 21:35:00 Top

dotnet-framework-aspnet >> shopping cart binding to datagrid
Flinky Wisty Pomm wrote:
> 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

 
Flinky Wisty Pomm





PostPosted: 2006-5-16 17:15:00 Top

dotnet-framework-aspnet >> shopping cart binding to datagrid 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