autocomplete控件没出错,但结果出不来
webservice.cs:[System.Web.Script.Services.ScriptService]
public class AutoComplete : System.Web.Services.WebService
{
public AutoComplete()
{
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public string[] GetCompleteDepart( string prefixText ,int count)
{
string[] autoCompleteWordList = null;
if (autoCompleteWordList == null)
{
//读取数据库的内容
string s = "Data Source=.;Initial Catalog=tianqiyubao;Integrated Security=True";
SqlConnection conn = new SqlConnection(s);
conn.Open();
string Snn = "select Top " + count + "city from tqyb where city like'" + prefixText + "%' order by cityUpdateTime";
SqlDataAdapter da = new SqlDataAdapter(Snn, conn);
DataSet ds = new DataSet();
da.Fill(ds);
string[] temp = new string[ds.Tables[0].Rows.Count];
int i = 0;
foreach (DataRow dr in ds.Tables[0].Rows)
{
temp[i] = dr["city"].ToString();
i++;
}
//将临时数组的内容赋给返回数组
autoCompleteWordList = temp;
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
}
String[] returnValue = new string[count];
returnValue = autoCompleteWordList;
//返回数据
return returnValue;
}
}
页面:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Label ID="Label1" runat="server" Text="请输入:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" ServiceMethod="GetCompleteDepart" ServicePath="AutoComplete.asmx" UseContextKey="True" Enabled="true" MinimumPrefixLength="1" CompletionSetCount="10" TargetControlID="TextBox1" FirstRowSelected="True" CompletionInterval="100">
</asp:AutoCompleteExtender>
</asp:Content>
补充:.NET技术 , Web Services