protected void btnAdd_Click(object sender, EventArgs e) { int saleId = Convert.ToInt32(hdnSaleId.Value); //lblcheckDoubleError.Text = string.Empty; int productId = Convert.ToInt32(ddlproduct.SelectedValue); decimal enteredQuantity = Convert.ToDecimal(txtquantity.Text); try { var productDetails = context.sp_GetSaleDetailsById(saleId).ToList(); if (productDetails != null) { var oneproductDetail = productDetails.Where(w => w.product_id == productId); if (!Convert.ToBoolean(ValidateQuantity(enteredQuantity, productId, saleId)[0])) { decimal subTotal = Convert.ToDecimal(txtquantity.Text) * Convert.ToDecimal(oneproductDetail.FirstOrDefault().sale_rate); decimal a = subTotal / 100; decimal discount_percent = (Convert.ToDecimal(oneproductDetail.FirstOrDefault().dicount_amt) * 100) / Convert.ToDecimal(oneproductDetail.FirstOrDefault().amount); decimal discountamt = a * Convert.ToDecimal(discount_percent.ToString("0.##")); decimal tax_amount = a * Convert.ToDecimal(oneproductDetail.FirstOrDefault().tax_percentage); clr(); calculation(subTotal, tax_amount, discountamt); txtPaidAmt.Enabled = true; DataTable tbl = (DataTable)ViewState["Details"]; tbl.Rows.Add(oneproductDetail.FirstOrDefault().saledetails_id, productId, oneproductDetail.FirstOrDefault().batch_id, oneproductDetail.FirstOrDefault().unit_id, oneproductDetail.FirstOrDefault().tax_id, subTotal, discountamt, tax_amount, oneproductDetail.FirstOrDefault().sale_rate, enteredQuantity, oneproductDetail.FirstOrDefault().product_name, oneproductDetail.FirstOrDefault().unit_name, oneproductDetail.FirstOrDefault().batch_name, oneproductDetail.FirstOrDefault().tax_percentage); ViewState["Details"] = tbl; this.BindGrid(); ddlproduct.Items.FindByValue(productId.ToString()).Enabled = false; } } } catch (Exception ex) { ErrorLog.saveerror(ex); } }