protected void GridView3_RowCommand(object sender, GridViewCommandEventArgs e) { if (sessionCust != null) { sessionCart = new Cart(sessionCust.CustomerID, 1); //Get the button clicked. Button btnAddToCart = ((Button)e.CommandSource); //get the row the button lives in GridViewRow currentRow = ((GridViewRow)btnAddToCart.NamingContainer); //find the quantity text box TextBox txtQuantity = ((TextBox)currentRow.FindControl("txtQuantity")); Int32 qty = Convert.ToInt32(txtQuantity.Text); //get the row's datakey value by keyname using .Values["keyname"] or if you only have one datakey field you can just use .Value Int32 prodId = Convert.ToInt32(GridView3.DataKeys[currentRow.RowIndex].Values["ProductID"].ToString()); //pass the quantity value and the prodid to your AddToCart method. //CartFunctions.AddItemToCart(prodId, txtQuantity.Text, 0.0M); sessionCart.AddToCart(prodId, qty); //Response.Write for testing only.. lblAddToCart.Text = txtQuantity.Text + " of ProductID " + prodId + " added to cart."; } else Response.Write("Error: no customer is in session."); }