C# WebVC的dropdownlist中的输入字符串格式不正确
我正在尝试将我自己创建的web服务与我的web应用程序集成在一起。在我的WebVC中,我创建了如下方法C# WebVC的dropdownlist中的输入字符串格式不正确,c#,asp.net,web-services,C#,Asp.net,Web Services,我正在尝试将我自己创建的web服务与我的web应用程序集成在一起。在我的WebVC中,我创建了如下方法 public double CarTaxwithOMV(int coetax) { double coe = coetax; if (coetax == 1) { coe = 1.3; } else if (coetax == 2) { c
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;
}
}
然后在我的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 + ".";
在我的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>
有人知道这个错误是怎么来的吗?您之所以会遇到这个错误,是因为您试图将字符串转换为整数 你的线路
int coe = Convert.ToInt32("DropDownList1.SelectedValue");
应该是
int coe = Convert.ToInt32(DropDownList1.SelectedValue);
另一方面,我还建议您使用而不是convert.ToInt32您没有从
CarTaxwithOMV
方法返回值。而且
Convert.ToInt32(“DropDownList1.SelectedValue”)代码>应该是
Convert.ToInt32(DropDownList1.SelectedValue);
您正在尝试转换字符串值而不是整数。从此行中删除quatation convert.ToInt32(“DropDownList1.SelectedValue”);
Convert.ToInt32(DropDownList1.SelectedValue);