Jes Sie

Jes Sie

  • 735
  • 1.2k
  • 284.5k

Unable to cast object of type 'System.Web.UI.WebControls.Tex

Oct 4 2017 3:49 AM
I am trying to update a template in a gridview but it gaves me this error:
 
Unable to cast object of type 'System.Web.UI.WebControls.TextBox' to type 'System.IConvertible'.
 
Below is my code behind.
  1. int rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex;  
  2.   
  3. int id = Convert.ToInt32(e.CommandArgument);  
  4. string option = ((TextBox)GridView1.Rows[rowIndex].FindControl("TextBox1")).Text;  
  5. string day = ((TextBox)GridView1.Rows[rowIndex].FindControl("TextBox2")).Text;  
  6. decimal netpremium = Convert.ToDecimal(((TextBox)GridView1.Rows[rowIndex].FindControl("TextBox3")));  
  7. decimal vat = Convert.ToDecimal(((TextBox)GridView1.Rows[rowIndex].FindControl("TextBox4")));  
  8. decimal registry = Convert.ToDecimal(((TextBox)GridView1.Rows[rowIndex].FindControl("TextBox5")));  
  9. decimal totalpremium = Convert.ToDecimal(((TextBox)GridView1.Rows[rowIndex].FindControl("TextBox6")));  
  10. TravelAssuranceDataAccess.UpdatePremium(id, option, day, netpremium, vat, registry, totalpremium);  
  11. GridView1.EditIndex = -1;  
  12. BindGridViewData();  
Thanks in advance for any assistance. 

Answers (1)