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.You can bind to an ArrayList because its an IEnumerable. Or am I not
understanding?
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
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
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment