【发布时间】:2015-12-03 11:47:12
【问题描述】:
我正在使用 ASP.NET AJAX 控件和工具包在 .aspx 页面中自动完成 TextBox。 TextBox 用作与下拉列表相关的搜索字段。现在我只希望自动完成功能在选择下拉列表中的某个类别时显示。
对于自动完成,我有这个代码
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string[] DepartmentAuto(string prefixText, int count)
{
string[] _strArray = { "Factory Management", "Housekeeping", "HR", "Industry Development"}
return _strArray;
}
我的下拉/文本框是这样工作的
void Filter()
{
if (DropDownList1.SelectedValue.ToString() == "Title")
{
ObjectDataSource1.FilterExpression = "Title LIKE '%" + TextBox1.Text + "%' ";
}
else if (DropDownList1.SelectedValue.ToString() == "Department")
{
ObjectDataSource1.FilterExpression = "Department LIKE '%" + TextBox1.Text + "%' ";
}
}
我尝试像这样将 if 语句添加到我的自动完成代码中
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string[] DepartmentAuto(string prefixText, int count)
{
if (DropDownList1.SelectedValue.ToString() == "Department")
{
string[] _strArray = { "Factory Management", "Housekeeping", "HR", "Industry Development"}
return _strArray;
}
}
然后我得到两个错误-
DepartmenAuto:并非所有代码路径都返回值
非静态字段、方法或属性“DropdownList1”需要对象引用
有什么帮助吗?
【问题讨论】:
-
错误是不言自明的 #1 你只在 if 语句中返回一个数组字符串,如果你的条件不满足怎么办。 #2 你不能在静态方法中使用实例元素,即你的下拉列表