title: how to convert a viewstate value to a integer variable
body: <p>i have the following code</p>
  
  <pre><code>private void ShowBill(int Prof_id,int Plan_id)
  {
      dt = new DataTable();
      dt = objmatportal.CreateBill(Prof_id, Plan_id);
      if (dt.Rows.Count &gt; 0)
      {
          lblbillto.Text = dt.Rows[0]["CONT_FNAME"].ToString() + " " + dt.Rows[0]["CONT_LNAME"].ToString() + "" + dt.Rows[0]["CONT_STATE"].ToString() + "" + dt.Rows[0]["CONT_CITY"].ToString();
          lblpayTo.Text = dt.Rows[0]["PAYTO"].ToString();
          lblDescription.Text = dt.Rows[0]["PLAN_NAME"].ToString();            
          lblAmount.Text ="Rs. "+string.Format("{0:0.00}",dt.Rows[0]["AMOUNT"]);
          lblTax.Text ="Rs. " +string.Format("{0:0.00}", dt.Rows[0]["VAT"]);
          LblTotal.Text ="Rs. "+ string.Format("{0:0.00}", dt.Rows[0]["TOTAL"]);
          ViewState["Total"] = dt.Rows[0]["TOTAL"].ToString();
      }
      else
      {
          Response.Write("Something gone wrong");
      }
  
  }
  </code></pre>
  
  <p>on the above method 
  on the line ViewState["Total"] = dt.Rows[0]["TOTAL"].ToString(); 
  i have assign the value to ViewState["Total"]</p>
  
  <p>but when i run  the following method it shows the error "Specified cast is not valid." on following line</p>
  
  <blockquote>
    <p>Total = (int)(ViewState["Total"]);</p>
  </blockquote>
  
  <pre><code>public int TotalwithConvenience()
  {
          int Total=0;
          decimal percentage = decimal.Parse(ViewState["CARD_PERCENT"].ToString());
          Total = (int)(ViewState["Total"]);
          decimal TDR = Total * percentage / 100;
          TDR = Math.Round(TDR);
          int tdrchrges = Convert.ToInt32(TDR.ToString());
          ViewState["convenience"] = tdrchrges;
          Total = Total + tdrchrges;
          return Total;
  
  }
  </code></pre>
  
  <p>need help to how to solve this </p>