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);
LinqDataSource1.Insert(lstNewValues);
Response.Redirect("PonudiNaAgencii.aspx");
}
}

Also I used LinqDataSource to connect dropdownlists.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.