2010-06-14 137 views
3

hello mates我想將下拉列表中的值存儲到整數,但我收到一個異常輸入字符串格式不正確。將下拉列表轉換爲int

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

請大家幫忙。

回答

7

刪除引號;它所代表的代碼試圖將文字字符串"DropDownList1.SelectedValue"轉換爲它不能的整數。

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

嘗試沒有引號:

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