从int到字符串转换一个eval价值 [英] Converting value of an Eval from int to string
本文介绍了从int到字符串转换一个eval价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有存储在我的数据库的一个整数,我需要转换的字符串。
I have an integer stored in my database that I need to convert string.
这是我在评估和演示的尝试:
This is my attempt at the Eval:
<%# ChangeSalaryType(Eval("SalaryType")) %>
这是我尝试在函数:
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;
}
但我得到这些错误:
But I am getting these errors:
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
我曾用SalaryType的评估和演示,因为这是一个具有从数据库中我不completetly知道我做错了。信息的参数。
I have used "SalaryType" in the Eval as that is the parameter that has the information from the database in. I'm not completetly sure what I am doing wrong..
推荐答案
即使你知道 SalaryType
字段将是一个 INT
在你的aspx它将评估和演示后转换为对象
()。做一个明确的转换,像这样:
Even though you know that the SalaryType
field will be an int
in your aspx it will be cast as object
after the Eval(). Do an explicit cast like so:
<%# ChangeSalaryType(Convert.ToInt32(Eval("SalaryType"))) %>
这篇关于从int到字符串转换一个eval价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文