title: shoppingcart using gridview asp.net
body: <p>I am creating a shopping cart using asp.net</p>
  
  <p>I following a tutorial that I've found online.
  I'm using gridview to view the cart after I've added it in.
  However,
  I don't know why, when I add a item,
  it doesn't show in the grid view.</p>
  
  <p>I did a calculation, adding all the items together.
  The calculation does show. It's just that my item in the grid view doesn't seems to be showing. </p>
  
  <pre><code>&lt;asp:GridView ID="CartList" runat="server" 
          AutoGenerateColumns="false" 
          ShowFooter="True"
          GridLines="Vertical" 
          CellPadding="4" 
          ItemType="MyWebStore.Models.CartItem" 
          SelectedMethod="GetShoppingCartItems"
          CssClass="table table-striped table-bordered"&gt;
      &lt;Columns&gt;
          &lt;asp:BoundField DataField="ProductID" HeaderText="ID" SortExpression="ProductID" /&gt;
          &lt;asp:BoundField DataField="Products.ProductName" HeaderText="Name" /&gt;
          &lt;asp:BoundField DataField="Products.UnitPrice" HeaderText="Price (each)" DataFormatString="{0:c}" /&gt;
          &lt;asp:TemplateField HeaderText="Quantity"&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:TextBox ID="PurchaseQuantity" runat="server" Width="40" Text="&lt;%#: Item.Quantity %&gt;"&gt;
                  &lt;/asp:TextBox&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:TemplateField HeaderText="Item Total"&gt;
              &lt;ItemTemplate&gt;
                  &lt;%#: String.Format("{0:c}",((Convert.ToDouble(Item.Quantity)) * Convert.ToDouble(Item.Product.UnitPrice))) %&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:TemplateField HeaderText="Remove Item"&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:CheckBox ID="Remove" runat="server"&gt;&lt;/asp:CheckBox&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
      &lt;/Columns&gt;
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>Code-behind</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
      {
          decimal cartTotal = 0;
          cartTotal = usersShoppingCart.GetTotal();
          if (cartTotal &gt; 0)
          {
              //Display total
              lblTotal.Text = String.Format("{0:c}", cartTotal);
          }
          else
          {
              LabelTotalText.Text = "";
              lblTotal.Text = "";
              ShoppingCartTitle.InnerText = "Shopping Cart is Empty";
          }
      }
  }
  
  public List&lt;CartItem&gt; GetShoppingCartItems()
  {
      ShoppingCartActions actions = new ShoppingCartActions();
      return actions.GetCartItems();
  }
  
  protected void CartList_SelectedIndexChanged(object sender, EventArgs e)
  {
  
  }
  </code></pre>
  
  <p>CartItem class</p>
  
  <pre><code>public partial class CartItem
  {
      public string ItemID { get; set; }
      public string CartID { get; set; }
      public int Quantity { get; set; }
      public System.DateTime DateCreated { get; set; }
      public int ProductID { get; set; }
  
      public virtual Product Product { get; set; }
  }
  </code></pre>
  
  <p>Can someone tell me why?</p>
  
  <p>error</p>
  
  <pre><code>System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName) at System.Web.UI.DataBinder.Eval(Object container, String[] expressionParts) at System.Web.UI.DataBinder.Eval(Object container, String expression) at System.Web.UI.WebControls.BoundField.GetValue(Control controlContainer) at System.Web.UI.WebControls.BoundField.OnDataBindField(Object sender, EventArgs e) at System.Web.UI.Control.OnDataBinding(EventArgs e) at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) at System.Web.UI.Control.DataBind() at System.Web.UI.Control.DataBindChildren() at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) at System.Web.UI.Control.DataBind() at System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource) at System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) at System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) at System.Web.UI.WebControls.DataBoundControl.PerformSelect() at System.Web.UI.WebControls.BaseDataBoundControl.DataBind() at System.Web.UI.WebControls.GridView.DataBind() at System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() at System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() at System.Web.UI.Control.EnsureChildControls() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  </code></pre>