protected void btnUpdate_OnClick(object sender, EventArgs e)
        {
            string msg = string.Empty;

            SalesOrderBLL salesOrder = new SalesOrderBLL();
            DataTable dtPrdList = new DataTable();
            DataRow dr = null;
            decimal quantity = 0;
            double rate = 0;
            double amount = 0;
            TextBox orderQuantityTextBox;
            TextBox ratePerUnitTextBox;
            TextBox amountTextBox;
            TextBox heighTextBox;
            TextBox widthTextBox;
            TextBox UnitTextBox;
            TextBox totalUnitTextBox;
            Label vatLabel;
            Label SerialLabel;
            int i = 0;

            dtPrdList.Columns.Add(new DataColumn("ProductId"));
            dtPrdList.Columns.Add(new DataColumn("Height"));
            dtPrdList.Columns.Add(new DataColumn("Width"));
            dtPrdList.Columns.Add(new DataColumn("OrderUnit"));
            dtPrdList.Columns.Add(new DataColumn("TotalUnit"));
            dtPrdList.Columns.Add(new DataColumn("OrderQuantity"));
            dtPrdList.Columns.Add(new DataColumn("Quantity"));
            dtPrdList.Columns.Add(new DataColumn("RatePerUnit"));
            dtPrdList.Columns.Add(new DataColumn("VATPercentage"));
            dtPrdList.Columns.Add(new DataColumn("Amount"));
            dtPrdList.Columns.Add(new DataColumn("Serial"));



            try
            {
                for (i = 0; i < selectedProductListGridView.Rows.Count; i++)
                {
                    //double availAbleQuantity = Convert.ToDouble(selectedProductListGridView.Rows[i].Cells[3].Text.ToString());
                    heighTextBox = (TextBox)selectedProductListGridView.Rows[i].FindControl("heightTextBox");
                    widthTextBox = (TextBox)selectedProductListGridView.Rows[i].FindControl("WidthTextBox");
                    UnitTextBox = (TextBox)selectedProductListGridView.Rows[i].FindControl("UnitTextBox");
                    totalUnitTextBox = (TextBox)selectedProductListGridView.Rows[i].FindControl("totalUnitTextBox");
                    orderQuantityTextBox = (TextBox)selectedProductListGridView.Rows[i].FindControl("orderQuantityTextBox");
                    ratePerUnitTextBox = (TextBox)selectedProductListGridView.Rows[i].FindControl("ratePerUnitTextBox");
                    amountTextBox = (TextBox)selectedProductListGridView.Rows[i].FindControl("amountTextBox");
                    vatLabel = (Label)selectedProductListGridView.Rows[i].FindControl("lblVatparcentage");
                    SerialLabel = (Label)selectedProductListGridView.Rows[i].FindControl("SerialLabel");
                    if (string.IsNullOrEmpty(orderQuantityTextBox.Text.Trim()) || !decimal.TryParse(orderQuantityTextBox.Text.Trim(), out quantity))
                    {
                        msg = "Product ID [" + selectedProductListGridView.Rows[i].Cells[0].Text.ToString() + "] has no valid quantity.";
                        msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = msg;
                        return;
                    }
                    else if (string.IsNullOrEmpty(ratePerUnitTextBox.Text.Trim()) || !double.TryParse(ratePerUnitTextBox.Text.Trim(), out rate))
                    {
                        msg = "Product ID [" + selectedProductListGridView.Rows[i].Cells[0].Text.ToString() + "] has no valid rate.";
                        msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = msg;
                        return;
                    }
                    else if (string.IsNullOrEmpty(amountTextBox.Text.Trim()) || !double.TryParse(amountTextBox.Text.Trim(), out amount))
                    {
                        msg = "Product ID [" + selectedProductListGridView.Rows[i].Cells[0].Text.ToString() + "] has no valid amount.";
                        msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = msg;
                        return;
                    }
                    //else if (Convert.ToDouble(orderQuantityTextBox.Text) > availAbleQuantity)
                    //{
                    //    msg = "Product ID [" + selectedProductListGridView.Rows[i].Cells[0].Text.ToString() + "] has no valid Availability.";
                    //    msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = msg;
                    //    return;
                    //}
                    else
                    {
                        dr = dtPrdList.NewRow();

                        dr["ProductId"] = selectedProductListGridView.Rows[i].Cells[0].Text.ToString();
                        // dr["Available"] = selectedProductListGridView.Rows[i].Cells[3].Text.ToString();
                        dr["Height"] = heighTextBox.Text;
                        dr["Width"] = widthTextBox.Text;
                        dr["OrderUnit"] = UnitTextBox.Text;
                        dr["TotalUnit"] = totalUnitTextBox.Text;
                        dr["Quantity"] = quantity.ToString();
                        dr["RatePerUnit"] = rate.ToString();
                        dr["VATPercentage"] = vatLabel.Text; //selectedProductListGridView.Rows[i].Cells[8].Text.ToString();
                        dr["Amount"] = amount.ToString();
                        dr["Serial"] = SerialLabel.Text;

                        dtPrdList.Rows.Add(dr);
                    }
                }

                salesOrder.SalesRecordId = idLabel.Text.Trim();
                salesOrder.JournalNumber = journalVoucharLavel.Text;
                salesOrder.SalesCenterId = salesCenterIdLabel.Text.Trim();
               // salesOrder.CustomerId = customerIdLabel.Text.Trim();
               // salesOrder.CustomerName = customerNameLabel.Text.Trim();
               // salesOrder.CustomerContactNumber = customerContactLabel.Text.Trim();
                //salesOrder.CustomerAddress = customerAddressLabel.Text.Trim();
                salesOrder.TotalAmount = totalAmountTextBox.Text.Trim();
                salesOrder.DiscountAmount = discountTextBox.Text.Trim();
                salesOrder.VAT = vatTextBox.Text.Trim();
                salesOrder.TotalReceivable = receivableAmountTextBox.Text.Trim();
              //  salesOrder.Due = "0";//DuesAmoutPayTextBox.Text;
                //salesOrder.SalesOrderId = "";
                salesOrder.ReceivedAmount = receivedAmountTextBox.Text.Trim();
                salesOrder.ChangeAmount = (Convert.ToDecimal(salesOrder.ReceivedAmount) - Convert.ToDecimal(salesOrder.TotalReceivable)).ToString();
                // salesOrder.TotalVATAmount = ;

               // salesOrder.AccountId = accountIdLabel.Text;
                //salesOrder.CustomerId = customerIdDropDownList.SelectedValue.Trim();
               // salesOrder.PaymentMode = paymentMethodLavel.Text.Trim();
                // receivePayment.Amount = receivedAmountTextBox.Text.Trim();
               // salesOrder.Bank = banklabel.Text.Trim();
               // salesOrder.BankBranch = bankBranchlabel.Text.Trim();
              //  salesOrder.ChequeNumber = ChequeNumberLavel.Text.Trim();
              //  salesOrder.ChequeDate = LumexLibraryManager.ParseAppDate(ChequeDateLavel.Text);
                salesOrder.OthersDes = txtbxDescription.Text;
                salesOrder.OthersAmount = txtbxOthersAmount.Text.Trim();
                salesOrder.Narration = txtbxNarration.Text;
                

                if (dtPrdList.Rows.Count == selectedProductListGridView.Rows.Count)
                {
                    string salesRecordId = salesOrder.UpdateRetailSales(dtPrdList);
                    if (salesRecordId != "")
                    {
                        //IPOSReportBLL iposReport = new IPOSReportBLL();
                        //iposReport.GetSalesInvoiceBySalesRecord(salesRecordId, salesOrder.SalesCenterId);
                        //ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "ViewReportForm();", true);

                        string message = "Product's <span class='actionTopic'>Sales</span> Successfully Updated in Sale ID: <span class='actionTopic'>" +
                        salesRecordId + "</span>.";
                        MyAlertBox("var callbackOk = function () { MyOverlayStart(); window.location = \"/UI/Sales/RetailSalesList.aspx\"; }; SuccessAlert(\"" +
                            "Process Succeed" + "\", \"" + message + "\", callbackOk);");
                    }

                    else
                    {
                        string message = "Product's <span class='actionTopic'>Sales</span>Update Falied" +
                        salesRecordId + "</span>.";
                        MyAlertBox("var callbackOk = function () { MyOverlayStart(); window.location = \"/UI/Sales/RetailSalesList.aspx\"; }; SuccessAlert(\"" +
                            "Process Succeed" + "\", \"" + message + "\", callbackOk);");
                    }

                }

            }
            catch (Exception ex)
            {
                string message = ex.Message;
                if (ex.InnerException != null) { message += " --> " + ex.InnerException.Message; }
                MyAlertBox("ErrorAlert(\"" + ex.GetType() + "\", \"" + message + "\", \"\");");
            }
            finally
            {
                salesOrder = null;
                dtPrdList = null;
            }
        }