当我为下拉列表实现代码时,我不断收到此错误。这是我的代码:
String sort = "";
String day_hire = "Daily hire rate";
String man_date = "Manufacturing date";
string man_n = "Manufacturer's name";
if (sl2.SelectedValue.ToString()== man_n)
{
sort = "man.manufacturer_name";
}
else if (sl2.SelectedValue.ToString() == man_date)
{
sort = "veh.manufacturing_date";
}
else if (sl2.SelectedValue.ToString() == day_hire)
{
sort = "veh.daily_hire_rate";
}
else
{
sort = "veh.daily_hire_rate";
}
这是在构造函数中。鉴于我有:
<%=Html.DropDownList ("sort",((SelectList)ViewData["selectOptions2"]))%>
这是一个运行时错误,显示sl2.SelectedValue.ToString()
为空。请帮忙