Linq Inconsistency
Can anyone help explain why when I bind the following code to a gridview, the negative numbers come out as 0.00?
var shoppingCartItems2 = Checkout.GetPr开发者_如何转开发opertyListingShoppingCartItems(SC.ShoppingCartID);
var columns = from sci in shoppingCartItems2
select new { Description = sci.ShoppingCartItemTypeL.Description, Price = sci.ShoppingCartItemTypeL.Price, ShoppingCartItemID = sci.ShoppingCartItemID };
ShoppingCartItemTypeGridView.DataSource = columns;
ShoppingCartItemTypeGridView.DataBind();
The "Price" field in shoppingCartItems2 has the correct value for each of the returned items, but when I create a new object (columns) in order to bind further down the object chain, the negative price (a discount) shows on the gridview as 0. It still calculates the total price correct, and it is negative in the database.
Any ideas?
What type is sci.ShoppingCartItemTypeL.Price?
Have you tried casting it to an int? Price = (int)sci.ShoppingCartItemTypeL.Price
?
精彩评论