title: Multiply 2 Columns and generate total from asp table
body: <p>I am developing simple billing website. The database is in Access 2013 of *.mdb format. And language used is c# .net</p>
  
  <p>Now, 
  I have a table in the Home.aspx file</p>
  
  <pre><code>&lt;fieldset&gt;
         &lt;asp:Table ID="DisplayTable" runat="server" CssClass="pure-table-horizontal" align="center"&gt;&lt;/asp:Table&gt;
      &lt;/fieldset&gt;
  </code></pre>
  
  <p>This table is Flooded on runtime by following code in Home.aspx.cs</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      //Use a string variable to hold the ConnectionString.
      string connectString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=  C:\Users\Raunaq\Documents\Visual Studio 2013\WebSites\BookStore\Database\Database.mdb";
      //Create an OleDbConnection object, 
      //and then pass in the ConnectionString to the constructor.
      OleDbConnection cn = new OleDbConnection(connectString);
  
      //Open the connection.
      cn.Open();
  
      //Use a variable to hold the SQL statement.
      string selectString = "SELECT Book_ID, Book_Name, Cost FROM Book_Details";
  
      //Create an OleDbCommand object.
      //Notice that this line passes in the SQL statement and the OleDbConnection object
      OleDbCommand cmd = new OleDbCommand(selectString, cn);
  
      //Send the CommandText to the connection, and then build an OleDbDataReader.
      //Note: The OleDbDataReader is forward-only.
      OleDbDataReader reader = cmd.ExecuteReader();
  
      //Set a table width.
      DisplayTable.Width = Unit.Percentage(50.00);
      //Create a new row for adding a table heading.
      TableRow tableHeading = new TableRow();
  
      //Create and add the cells that contain the Customer ID column heading text.
      TableHeaderCell customerIDHeading = new TableHeaderCell();
      customerIDHeading.Text = "ID";
      customerIDHeading.HorizontalAlign = HorizontalAlign.Left;
      tableHeading.Cells.Add(customerIDHeading);
  
      //Create and add the cells that contain the Contact Name column heading text.
      TableHeaderCell contactNameHeading = new TableHeaderCell();
      contactNameHeading.Text = "Book Name";
      contactNameHeading.HorizontalAlign = HorizontalAlign.Left;
      tableHeading.Cells.Add(contactNameHeading);
  
      //Create and add the cells that contain the Phone column heading text.
      TableHeaderCell phoneHeading = new TableHeaderCell();
      phoneHeading.Text = "Price";
      phoneHeading.HorizontalAlign = HorizontalAlign.Left;
      tableHeading.Cells.Add(phoneHeading);
  
      TableHeaderCell quan = new TableHeaderCell();
      quan.Text = "Quantity";
      quan.HorizontalAlign = HorizontalAlign.Left;
      tableHeading.Cells.Add(quan);
  
  
      DisplayTable.Rows.Add(tableHeading);
  
      //Loop through the resultant data selection and add the data value
      //for each respective column in the table.
      while (reader.Read())
      {
          TableRow detailsRow = new TableRow();
          TableCell customerIDCell = new TableCell();
          customerIDCell.Text = reader["Book_ID"].ToString();
          detailsRow.Cells.Add(customerIDCell);
  
          TableCell contactNameCell = new TableCell();
          contactNameCell.Text = reader["Book_Name"].ToString();
          detailsRow.Cells.Add(contactNameCell);
  
          TableCell phoneCell = new TableCell();
          phoneCell.Text = reader["Cost"].ToString() + " " + "&amp;#8377;";
          detailsRow.Cells.Add(phoneCell);
  
          TableCell quanti = new TableCell();
          TextBox tb = new TextBox();
          tb.ID = reader["Book_ID"].ToString();
          tb.Text = "0";
          tb.Width = 66;
          quanti.Controls.Add(tb);
          detailsRow.Cells.Add(quanti);
  
          DisplayTable.Rows.Add(detailsRow);
  
      }
  
      //Close the reader and the related connection.
      reader.Close();
      cn.Close();
      Panel1.Visible = false;
  }
  </code></pre>
  
  <p>Now I have a button named 'Calculate' and I want to generate total based on the columns Price and Quantity.
  I tried many things but nothing seems to work till now.</p>
  
  <p>Kindly help me.
  Please tell me if you need anything else to understand my problem better.</p>
  
  <blockquote>
    <p>Thank you. Problem Solved.
    Solution</p>
  </blockquote>
  
  <pre><code> for (int i=1;i&lt;row_count;i++)
      {
          TextBox tc = (TextBox)DisplayTable.FindControl("tb" + i);
          int q1 = Convert.ToInt32(tc.Text);
          TableCell tcc = (TableCell)DisplayTable.FindControl("cost" + i);
          char[] trimchar;
          string trim = " " + "&amp;#8377;";
          trimchar = trim.ToCharArray();
          string a1 = tcc.Text.TrimEnd(trimchar);
          int a = Int32.Parse(a1);
          total_amt = q1 * a + total_amt;
      }
      Amount = total_amt;   
      Label1.Text = Amount.ToString() + "&amp;#8377;";
  </code></pre>