Object of type 'System.Web.UI.WebControls.TextBox' cannot be converted to type 'System.Int32'
6 minutes ago|LINK

Hi, i started web application in Microsoft Visual Web Developer 2010 Express. I created few text boxes and dropdown lists. I connect them with my database in SQL management studio. When I click on SaveButton it should be saved in the base table, but it shouldn't. I write this code on the save button click and when I run project it says:

Failed to set one or more properties on type x.y. Object of type 'System.Web.UI.WebControls.TextBox' cannot be converted to type 'System.Int32'.

How can I solve this. This is my first app, so if anyone could help with my trouble.... :D thanks

protected void Button_Click(object sender, EventArgs e)
ListDictionary lstNewValues = new ListDictionary();
lstNewValues.Add("OfferID", txtOfferID);
lstNewValues.Add("OfferName", txtOfferName);
lstNewValues.Add("OfferPeriod", ddOfferPeriod);
lstNewValues.Add("OfferPrice", txtOfferPrice);
lstNewValues.Add("OfferDetails", ddAgencyName);

Also I used LinqDataSource to connect dropdownlists.

5 Years
Discussion Span
Last Post by hericles

You need to use the text property of the text box if you want to access the text the text box contains. You are including the textbox itself in the list, not what it contains.

lstNewValues.Add("OfferID", txtOfferID.text);

You are seeing that error because a text box control cannot be converted into an integer.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.