VB.NET版 autoComplete 自动完成功能

前端之家收集整理的这篇文章主要介绍了VB.NET版 autoComplete 自动完成功能前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
   
 <script type="text/javascript" src="../Scripts/jquery-1.4.1.min.js"></script>
    <script src="../Scripts/jquery.autocomplete.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.autocomplete.min.js" type="text/javascript"></script>
    <link href="../Styles/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
    <script src="../Handler/GetPersonJson.ashx" type="text/javascript"></script>



//获取人员信息 搜索自动完成 result 回调函数返回结果
$("#txtPerson").keydown(function () {
$("#txtPerson").autocomplete(persondatas);
}).result(function (event,persondatas,formatted)
{ $("#txtPerson").val(persondatas.toString().split(' -- ')[0]);
})


GetPersonJson.ashx code as below:
     
            Dim connectionString As String = ConfigurationManager.ConnectionStrings("ConnectionString_EIS").ConnectionString
            
             

            
            ' EmployeeID
            
            Dim strsql As String = "  SELECT   (ChineseName + ' -- ' + EmployeeID) as Person  FROM [Employees]  where EmployeeID is not null  ORDER BY [EnglishName]"
  
            
            Dim da As sqlDataAdapter = New sqlDataAdapter(strsql,connectionString)
            
            da.Fill(ds)
                
 
              
            Dim jsonString As String = CreateJsonParameters(ds.Tables(0))
            
            Dim newJsonStr As String = String.Empty
            
' 定义persondatas 提供前台使用
            newJsonStr = "var persondatas=[" & jsonString & "]"
          
            
            context.Response.Write(newJsonStr)
                
                
        Catch ex As Exception
            Throw ex
        End Try





Public Function CreateJsonParameters(ByVal dt As DataTable) As String

        Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder()


        If dt IsNot Nothing Then
            sb.Append("[")

            For i = 0 To dt.Rows.Count - 1

                sb.Append("{")
                For j = 0 To dt.Columns.Count - 1
                    If j < dt.Columns.Count - 1 Then
                       'Chr(34) 是代表双引号
                        sb.Append(Chr(34) & dt.Columns(j).ColumnName.ToString() & Chr(34) & ":" & Chr(34) & dt.Rows(i)(j).ToString() & Chr(34) & ",")
                    ElseIf (j = dt.Columns.Count - 1) Then

                        sb.Append(Chr(34) & dt.Columns(j).ColumnName.ToString() & Chr(34) & ":" & Chr(34) & dt.Rows(i)(j).ToString() & Chr(34))


                    End If


                Next j

                If i = dt.Rows.Count - 1 Then

                    sb.Append("}")

                Else
                    sb.Append("},")

                End If


            Next i


        End If

        sb.Append("]")
        Return sb.ToString()

    End Function
原文链接:https://www.f2er.com/vb/258969.html

猜你在找的VB相关文章