autosuggest文本框显示列表 [英] autosuggest text box is showing the list
本文介绍了autosuggest文本框显示列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用自动建议框没有网络服务,它正确地重新传输数据库中的值,但它不会在网页上显示列表。
可以任何人帮助我
这里是我的HTML代码
< !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 = 服务器 >
< title > Untitled Page < / title >
< / head >
< body >
< 表格 id = form1 runat = server < span class =code-keyword>>
< div >
& nbsp; < cc1:ToolkitScriptManager ID = ToolkitScriptManager1 runat = server >
< / cc1:ToolkitScriptManager >
& nbsp;
< asp:TextBox ID = txtCountry < span class =code-attribute> runat = server > < / asp:TextBox >
< cc1:AutoCompleteExtender ID = AutoCompleteExtender1 runat = server TargetControlID = txtCountry
MinimumPrefixLength = 1 EnableCaching = true CompletionSetCount = 1 CompletionInterval = 1000 ServiceMethod = GetCountries >
< / cc1:AutoCompleteExtender >
< / div >
< / form >
< / body >
< / html >
这是我的代码
Imports System.Data
Imports System.Data .SqlClient
Imports System.Collections.Generic
Imports System.Configuration
部分 类 Default2
继承 System.Web.UI.Page
受保护的 Sub Page_Load(< span class =code-keyword> ByVal sender 作为 对象, ByVal e As System.EventArgs)句柄 我。加载
End Sub
< system.web.script.services.scriptmethod()> _
< system.web.services.webmethod()> _
公开 共享 功能 GetCountries( ByVal prefixText As String )< span class =code-keyword> As List( Of String )
Dim con As 新 SqlConnection(ConfigurationManager) .ConnectionStrings( appraisalConnectionString)。ToString())
con.Open()
Dim cmd 作为 新 SqlCommand ( select * from tblCountry,其中CountryName类似@Name +'%',con)
CMD。 Parameters.AddWithValue( @ Name,prefixText)
Dim da As 新 SqlDataAdapter(cmd)
Dim dt As 新 DataTable()
da.Fill(dt)
Dim CountryNames As 新列表( 字符串)()
For i As Integer = 0 dt.Rows.Count - 1
CountryNames.Add (dt.Rows(i)( 1 )。ToString())
下一步
返回 CountryNames
结束 功能
结束 Class
解决方案
Hello Supriya,
尝试增加CompletionSetCount
。根据文档,Service方法的签名应如下所示。
[System.Web.Services.WebMethod]
[System.Web.Script .Services.ScriptMethod]
public string [] GetCompletionList(string prefixText,int count)
我还建议你通过这个[^ ]文章。
的问候,
i use the auto suggest box without web serivce it reteriving the value from the database properly but it will not show the list on the web page.
can any one help me
here is my html code
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</cc1:ToolkitScriptManager>
<asp:TextBox ID="txtCountry" runat="server"></asp:TextBox>
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtCountry"
MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1" CompletionInterval="1000" ServiceMethod="GetCountries" >
</cc1:AutoCompleteExtender>
</div>
</form>
</body>
</html>
and it is my code
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections.Generic
Imports System.Configuration
Partial Class Default2
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
<system.web.script.services.scriptmethod()> _
<system.web.services.webmethod()> _
Public Shared Function GetCountries(ByVal prefixText As String) As List(Of String)
Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("appraisalConnectionString").ToString())
con.Open()
Dim cmd As New SqlCommand("select * from tblCountry where CountryName like @Name+'%'", con)
cmd.Parameters.AddWithValue("@Name", prefixText)
Dim da As New SqlDataAdapter(cmd)
Dim dt As New DataTable()
da.Fill(dt)
Dim CountryNames As New List(Of String)()
For i As Integer = 0 To dt.Rows.Count - 1
CountryNames.Add(dt.Rows(i)(1).ToString())
Next
Return CountryNames
End Function
End Class
解决方案
Hello Supriya,
Try increasingCompletionSetCount
. As per documentation the signature of the Service method should be as shown below.
[System.Web.Services.WebMethod] [System.Web.Script.Services.ScriptMethod] public string[] GetCompletionList(string prefixText, int count)
I will also recommend you to go through this[^] article.
Regards,
这篇关于autosuggest文本框显示列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文