Convert unpack list to int

Hi, I am trying to save a value from a drop-down list to an integer, but I get an exception. The input string was not in the correct format.

int experienceYears = Convert.ToInt32("DropDownList1.SelectedValue");

Please, help.

+3
source share
2 answers

Remove quotation marks; the code in its current form is trying to convert a literal string "DropDownList1.SelectedValue"to an integer, which cannot be.

int experienceYears = Convert.ToInt32(DropDownList1.SelectedValue);
+7
source

Try it without quotes:

int experienceYears = Convert.ToInt32(DropDownList1.SelectedValue);
+1
source

Source: https://habr.com/ru/post/1749971/


All Articles