protected void AgregarButton_Click(object sender, EventArgs e) { Entrada entrada = new Entrada(); decimal total = 0; int productoID = Utils.ToIntObjetos(ProductoDropdownList.SelectedValue); string descripcion = Metodo.Descripcion(productoID); entrada.Detalle = new List <EntradaDetalle>(); if (IsValid) { DateTime date = DateTime.Now.AddDays(7); entrada = (Entrada)ViewState["Entrada"]; decimal Importe = Convert.ToDecimal(CantidadTextBox.Text) * Convert.ToDecimal(CostoTextBox.Text); entrada.AgregarDetalle (0, Utils.ToInt(IdTextBox.Text), Utils.ToInt(ProductoDropdownList.SelectedValue), descripcion, Convert.ToDecimal(CantidadTextBox.Text), Convert.ToDecimal(CostoTextBox.Text), Importe, date); ViewState["Entrada"] = entrada; this.BindGrid(); foreach (var item in entrada.Detalle) { total += item.Importe; } TotalTextBox.Text = total.ToString(); } }