protected void btnPay_Click(object sender, EventArgs e) { DataTable PurchaseDetail = (DataTable)ViewState["SALE_TRANSACTION_TABLE"]; Decimal finalamount = 0; Decimal amountPaid = 0, amountDue = 0; foreach (DataRow dr in PurchaseDetail.Rows) { finalamount += Convert.ToDecimal(dr["AMOUNT"].ToString()); } totalAmount.Text = finalamount.ToString(); amountPaid = Convert.ToDecimal(Amountpaid.Text.Trim()); amountDue = finalamount - amountPaid; DataTable Purchase = new DataTable(); if (PurchaseDetail.Rows.Count > 0) { Purchase.Columns.Add("SUPPLIER_ID", typeof(int)); Purchase.Columns.Add("TOTAL_AMOUNT", typeof(decimal)); Purchase.Columns.Add("AMOUNT_PAID", typeof(decimal)); Purchase.Columns.Add("AMOUNT_DUE", typeof(int)); DataRow dr = Purchase.NewRow(); dr["SUPPLIER_ID"] = ddlSupplier.SelectedValue.ToString(); dr["TOTAL_AMOUNT"] = finalamount.ToString(); dr["AMOUNT_PAID"] = Amountpaid.Text.Trim(); dr["AMOUNT_DUE"] = amountDue.ToString(); Purchase.Rows.InsertAt(dr, 0); } stock.AddPurchaseTransaction(PurchaseDetail, Purchase); SECTION.Visible = true; paymentSection.Visible = false; }