前台AutoCompleteExtender.aspx代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AutoCompleteExtender.aspx.cs" Inherits="AutoCompleteExtender" %><%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <cc1:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server" 
            DelimiterCharacters="" Enabled="True" MinimumPrefixLength="1" 
            ServiceMethod="GetCompletionList" ServicePath="" TargetControlID="TextBox1" 
            UseContextKey="True">
        </cc1:AutoCompleteExtender>
    
    </div>
    </form>
</body>
</html>后台
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;public partial class AutoCompleteExtender : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {    }    [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
    public static string[] GetCompletionList(string prefixText, int count, string contextKey)
    {
        SqlConnection conn = new SqlConnection("Server=(Local);Uid=sa;pwd=15911113281;DataBase=db_Siemens");
        SqlCommand cmd;
        string cmdString = "select UserName from t_StaffInfo WHERE UserName LIKE '" + prefixText + "%'";
        //   "Select CompanyName from Customers WHERE CompanyName LIKE '" +
        //   prefixText + "%'";
        //conn = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
        //// Put this string on one line in your code
        cmd = new SqlCommand(cmdString, conn);
        conn.Open();        SqlDataReader myReader;
        List<string> returnData = new List<string>();        myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);        while (myReader.Read())
        {
            returnData.Add(myReader["UserName"].ToString());
        }        return returnData.ToArray();
    }
}为何运行时,在文本框输入后,无法检索出相关的呢??求助!!调了很久了!!

解决方案 »

  1.   

    ServicePath=""
    DelimiterCharacters=""

    是打错还是确实是空的?
      

  2.   


    如果你不会调试,“调了很久”也是白费。从你描述,看不出你在 GetCompletionList 中的断点调试操作体验,所以不知道你是否正确地“调了”。你的问题大概是出在 myReader.Read() 和 myReader["UserName"].ToString() 上,也就是说你至少应该在 return returnData.ToArray(); 这条语句上看看监视窗口中 returnData 的内容是否正确吧。
      

  3.   

    调试说
            if (!this._postBackSettings.async) {
                return;
            }
    中Microsoft JScript 运行时错误: 'this._postBackSettings.async' 为空或不是对象,我不明白是哪里错了~~