将下拉列表转换为整数

3

大家好,我正在尝试将下拉列表中的值存储到一个整数中,但是我遇到了异常"输入字符串格式不正确"

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

请帮忙。

2个回答

7

去掉引号;代码当前尝试将字面字符串“DropDownList1.SelectedValue”转换为整数,但它无法实现。

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

1

不带引号尝试一下:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接