[英]Input string was not in a correct format at dropdownlist from websvc
I'm trying to integrate my self-created web service together with my web-application. 我正在尝试将自己创建的Web服务与Web应用程序集成在一起。 In my websvc, i created a method like below.
在我的websvc中,我创建了如下方法。
public double CarTaxwithOMV(int coetax)
{
double coe = coetax;
if (coetax == 1)
{
coe = 1.3;
}
else if (coetax == 2)
{
coe=1.1;
}
else if (coetax == 3)
{
coe = 1;
}
}
Then in my web-application i tried to call the values above in my web-application 然后在我的Web应用程序中,我尝试在我的Web应用程序中调用上面的值
int coe = Convert.ToInt32("DropDownList1.SelectedValue");
double totalcost = tc.CarTaxwithOMV(coe);
lblinfo.Text = "Your total car tax for the above information is " + totalcost + ".";
In my aspx page, i have assigned a value with my dropdownlist options. 在我的aspx页面中,我使用dropdownlist选项分配了一个值。
<asp:ListItem Value="1">COEs obtained from May 2002 to February 2004 tender exercises</asp:ListItem>
<asp:ListItem Value="2">COEs obtained from March 2004 to February 2008 tender exercises.</asp:ListItem>
<asp:ListItem Value="3">COEs obtained from March 2008 onwards tender exercises.</asp:ListItem>
The value i declare in both my websvc and aspx page are all in integer. 我在websvc和aspx页面中声明的值都是整数。 However when i tried to call and obtain the value from the websvc method to my web application i got this error at the dropdownlist
但是,当我尝试从websvc方法调用并获取到我的Web应用程序的值时,我在dropdownlist上收到此错误
Input string was not in a correct format
Does anyone have any idea how does this error come from ? 有谁知道这个错误是怎么产生的?
You are getting this error because you are trying to convert string to integer. 由于尝试将字符串转换为整数,因此出现此错误。
your line 你的线
int coe = Convert.ToInt32("DropDownList1.SelectedValue");
should be 应该
int coe = Convert.ToInt32(DropDownList1.SelectedValue);
on a side note i would also recommend that you use int.TryParse instead of convert.ToInt32 在旁注中,我还建议您使用int.TryParse而不是convert.ToInt32
You didn't return a value from CarTaxwithOMV
method. 您没有从
CarTaxwithOMV
方法返回值。 And also Convert.ToInt32("DropDownList1.SelectedValue");
还有
Convert.ToInt32("DropDownList1.SelectedValue");
Should be 应该
Convert.ToInt32(DropDownList1.SelectedValue);
You are trying to convert a string value instead of a integer.. 您正在尝试转换字符串值而不是整数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.