ar31an
ar31an

Reputation: 263

Converting Dropdown list to int

hello mates i am trying to store value from dropdown list to an integer but i am getting an exception Input string was not in a correct format.

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

please help.

Upvotes: 3

Views: 5714

Answers (2)

Sani Huttunen
Sani Huttunen

Reputation: 24385

Try it without the quotes:

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

Upvotes: 1

Adam Robinson
Adam Robinson

Reputation: 185663

Remove the quotes; the code as it stands is trying to convert the literal string "DropDownList1.SelectedValue" to an integer, which it can't.

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

Upvotes: 7

Related Questions