我的gridview文本框有几个AutoCompleteExtender,它们在我的计算机上运行得很好,但是在我将它部署到服务器上之后,自动完成并没有显示任何内容,也没有错误。我比较了web.config和它们在程序集中的web.extentions相同,ajaxtoolkit版本也是相同的。我有calenderextender甚至在部署后也能正常工作。 这是我的gridview和webmethod。如果需要,我将添加web.config。谢谢!
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<script type="text/javascript" runat="server">
<System.Web.Services.WebMethod()> _
Public Shared Function GetCompletionList(ByVal prefixText As String, ByVal count As Integer, ByVal contextKey As String) As String()
If count = 0 Then
count = 10
End If
Dim collname As String = contextKey
Dim dt As DataTable = GetRecords(prefixText, collname)
Dim items As New List(Of String)(count)
For i As Integer = 0 To dt.Rows.Count - 1
Dim strName As String = dt.Rows(i)(0).ToString()
items.Add(strName)
Next
Return items.ToArray()
End Function
Public Shared Function GetRecords(ByVal strName As String, ByVal collname As String) As DataTable
Dim strConn As String = ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString
Dim con As New SqlConnection(strConn)
Dim cmd As New SqlCommand()
cmd.Connection = con
cmd.CommandType = System.Data.CommandType.Text
cmd.Parameters.AddWithValue("@testname", strName)
cmd.CommandText = "select Distinct " + collname + " from Test where " + collname + " LIKE '%' + @testName + '%'"
Dim objDs As New DataSet()
Dim dAdapter As New SqlDataAdapter()
dAdapter.SelectCommand = cmd
con.Open()
dAdapter.Fill(objDs)
con.Close()
Return objDs.Tables(0)
End Function
</script>
/*Gridview edit template */
<ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</ajaxToolkit:ToolkitScriptManager>
<EditItemTemplate>
<asp:TextBox ID="txttest" runat="server" Text='<%# Bind("testcol") %>'></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender
runat="server"
ID="AutoCompleteExtender"
TargetControlID="txttest"
ServiceMethod="GetCompletionList" MinimumPrefixLength="1" EnableCaching="true" ContextKey="testcol" UseContextKey="true"
CompletionSetCount="20" ViewStateMode="Inherit">
</ajaxToolkit:AutoCompleteExtender>