for (int i = 1; i <= dtCurrentTable.Rows.Count; i++) { TextBox box3 = (TextBox)ItemGv.Rows[rowIndex].Cells[2].FindControl("qtytb"); TextBox box4 = (TextBox)ItemGv.Rows[rowIndex].Cells[3].FindControl("upricetb"); TextBox box5 = (TextBox)ItemGv.Rows[rowIndex].Cells[4].FindControl("amounttb"); drCurrentRow = dtCurrentTable.NewRow(); drCurrentRow["Qty"] = box3.Text; drCurrentRow["UnitPrice"] = box4.Text; drCurrentRow["TotalAmount"] = box5.Text; //Total for (int j = 0; j < ItemGv.Columns.Count; j++) { total = Convert.ToInt32(box3.Text) * Convert.ToSingle(box4.Text); box5.Text = total.ToString(); } //subtotal for (int k = 0; k < ItemGv.Rows.Count; k++) { subtotal = subtotal + Convert.ToSingle(box5.Text); subtotaltb.Text = subtotal.ToString(); } rowIndex++;
private void AddNewRowToGrid() { int rowIndex = 0; float total; float subtotal = 0; if (ViewState["CurrentTable"] != null) { DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"]; DataRow drCurrentRow = null; if (dtCurrentTable.Rows.Count > 0) { for (int i = 1; i <= dtCurrentTable.Rows.Count; i++) { //extract the TextBox values TextBox box1 = (TextBox)ItemGv.Rows[rowIndex].Cells[0].FindControl("itemNotb"); TextBox box2 = (TextBox)ItemGv.Rows[rowIndex].Cells[1].FindControl("desctb"); TextBox box3 = (TextBox)ItemGv.Rows[rowIndex].Cells[2].FindControl("qtytb"); TextBox box4 = (TextBox)ItemGv.Rows[rowIndex].Cells[3].FindControl("upricetb"); TextBox box5 = (TextBox)ItemGv.Rows[rowIndex].Cells[4].FindControl("amounttb"); drCurrentRow = dtCurrentTable.NewRow(); drCurrentRow["ItemNo"] = box1.Text; drCurrentRow["Description"] = box2.Text; drCurrentRow["Qty"] = box3.Text; drCurrentRow["UnitPrice"] = box4.Text; drCurrentRow["TotalAmount"] = box5.Text; for (int j = 0; j < ItemGv.Columns.Count; j++) { total = Convert.ToInt32(box3.Text) * Convert.ToSingle(box4.Text); box5.Text = total.ToString(); } for (int k = 0; k < ItemGv.Rows.Count; k++) { subtotal = subtotal + Convert.ToSingle(box5.Text); subtotaltb.Text = subtotal.ToString(); } rowIndex++; }
ItemGv
for (int i = 1; i <= dtCurrentTable.Rows.Count; i++) { TextBox box3 = (TextBox)ItemGv.Rows[rowIndex].Cells[2].FindControl("qtytb"); TextBox box4 = (TextBox)ItemGv.Rows[rowIndex].Cells[3].FindControl("upricetb"); TextBox box5 = (TextBox)ItemGv.Rows[rowIndex].Cells[4].FindControl("amounttb"); drCurrentRow = dtCurrentTable.NewRow(); drCurrentRow["Qty"] = box3.Text; drCurrentRow["UnitPrice"] = box4.Text; drCurrentRow["TotalAmount"] = box5.Text; total = Convert.ToInt32(box3.Text) * Convert.ToSingle(box4.Text); box5.Text = total.ToString(); subtotal = subtotal + Convert.ToSingle(box5.Text); subtotaltb.Text = subtotal.ToString(); rowIndex++;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)