우리 회사와 비슷한 일을합니다. 이를 위해 AJAX를 통해 웹 서비스를 활용합니다.
기본적으로 AJAX AutoCompleteExtender (ACE)를 사용하여 표준 텍스트 상자를 수정합니다. 이 에이스는 고객이 직접 입력하는 정보를 가져 오는 웹 서비스 (내가 설명 할 것입니다)를 참조합니다. 일단 시작되고 실행되면 멋지다. 미묘한
<asp:TextBox ID="txtInsuranceCompany" runat="server" TabIndex="520"
AutoComplete="Off"AutoCompleteType="Disabled" CssClass="asbSearch" Width="350px"></asp:TextBox>
<ajax:AutoCompleteExtender ID="aceInsuranceCompany" runat="server" CompletionSetCount="20"
MinimumPrefixLength="0" OnClientShown="resetPosition" ServiceMethod="LookupData"
ServicePath="~/WebLookUpService.asmx" TargetControlID="txtInsuranceCompany" UseContextKey="true">
</ajax:AutoCompleteExtender>
뭔가
의 .ascx은 당신이 당신의 자동 완성 확장에 대한 컨텍스트 키를 설정뿐만 아니라 당신의 웹 서비스에서 일부 기능을 만들 확인해야한다는 것입니다 : 여기
은 예입니다 값을로드하십시오 (다시 설명 하겠습니다).
된 .vb 코드 숨김
Dim yourhardcodedlist As New List(Of String)
yourhardcodedlist.Add("Progressive")
yourhardcodedlist.Add("State Farm")
yourhardcodedlist.Add("USAA")
WebLookUpService.AddLookupValues(txtInsuranceCompany.ID, yourhardcodedlist.ToArray)
aceInsuranceCompany.ContextKey = public_var0 & ":" & public_var1 & ":" & txtInsuranceCompany.ID
참고 "public_var0" "와 public_var1는"필수 아니라는 것을. 이는 실제로 매개 변수로 전달하지 않고 웹 서비스에 더 많은 정보를 전달할 수있는 방법을 보여줍니다 (예 :콜론으로 구분 된 목록, 웹 서비스 기능이 SQL 문 등에서 사용할 수 있도록 구문 분석 할 수 있음). WebService에 대한 지금
(. ASMX는)
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class WebLookUpService
Inherits System.Web.Services.WebService
<System.Web.Services.WebMethod(), System.Web.Script.Services.ScriptMethod()> _
Public Function LookupData(ByVal prefixText As String, ByVal count As Integer, ByVal contextKey As String) As String()
'Construct SQL statement to pull from database
'parsing the context key as necessary to construct your SQL statement (if necessary)
'Dim somethingForSql As String = contextKey.Split(":")
Dim suggestions As List(Of String) = New List(Of String)
Try
Using cnADO As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("PublicSafetyServer").ToString)
cnADO.Open()
Dim dt As DataTable = New DataTable
Dim da As New SqlDataAdapter
da.SelectCommand = New SqlCommand("<YourSQLStatement>")
da.Fill(dt)
Dim endRow As Integer = dt.Rows.Count
If endRow > count Then
endRow = count
End If
For i As Integer = 0 To endRow - 1
Dim des As String = dt.Rows(i).Item(field)
Dim val As String = dt.Rows(i).Item(field)
suggestions.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(des, val))
Next
End Using
Catch ex As Exception
'Throw Error
End Try
suggestions.Sort()
If suggestions.Count = 0 Then
suggestions.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(noneFound, ""))
End If
Return suggestions.ToArray()
End Function
어떤 멋진 것은 당신이 의도적으로 사용자가 웹 서비스를 통해 끌어 모든 값과 결합 것 'yourhardcodedlist'을 통해 값을 추가 할 수 있다는 것입니다. 이렇게하면 데이터베이스에 값을 추가 할 수없는 경우 직접 값을 추가 할 수 있습니다.
Windows Forms 앱입니까, 웹 사이트입니까? – sacredfaith