protected void btnAddDetail_Click(object sender, EventArgs e) { Page.Validate("AddDetail"); if (Page.IsValid) { int id = Detail.Any() ? Detail.Max(row => row.ID) + 1 : 1; Item selectedItem = ItemService.Get(Convert.ToInt32(ddlItem.SelectedValue)); Detail.Add( new PackageDetailViewModel() { ID = id, ItemBarcode = selectedItem.Barcode, ItemDescription = selectedItem.Description, ItemID = selectedItem.ID, Quantity = Convert.ToInt32(txtQuantity.Text), UnitPrice = Convert.ToDecimal(txtUnitPrice.Text), UnitName = selectedItem.UnitName1 }); WebFormHelper.ClearTextBox(txtQuantity, txtUnitPrice); ddlItem.SelectedIndex = 0; gvwDetail.DataSource = Detail; gvwDetail.DataBind(); } }