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.
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);
Try it without the quotes:
int experienceYears = Convert.ToInt32(DropDownList1.SelectedValue);
精彩评论