我有一个整数存储在我的数据库中,我需要转换字符串.
这是我在Eval的尝试:
<%# ChangeSalaryType(Eval("SalaryType")) %>
Run Code Online (Sandbox Code Playgroud)
这是我对该功能的尝试:
public static string ChangeSalaryType(int salaryType)
{
string salaryTime = string.Empty;
if (salaryType == 1)
{
salaryTime = "per hour";
}
else if (salaryType == 2)
{
salaryTime = "per week";
}
else if (salaryType == 3)
{
salaryTime = "per annum";
}
return salaryTime;
}
Run Code Online (Sandbox Code Playgroud)
但我收到这些错误:
Argument 1: cannot convert from 'object' to 'int'
Error 2 The best overloaded method match for 'controls_allPlacements.ChangeSalaryType(int)' has some invalid arguments
Error 4 The best overloaded method match for 'controls_allPlacements.ChangeSalaryType(int)' has some invalid arguments
Run Code Online (Sandbox Code Playgroud)
我在Eval中使用了"SalaryType",因为这是具有来自数据库的信息的参数.我不完全确定我做错了什么..
Tah*_*aza 10
即使您知道该SalaryType字段将int在您的aspx中,它将object在Eval()之后进行转换.像这样做一个明确的演员:
<%# ChangeSalaryType(Convert.ToInt32(Eval("SalaryType"))) %>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18896 次 |
| 最近记录: |