2012-11-03 5 views
1

특정 문자를 입력 한 후 직원의 이름을 표시하는 자동 제안 텍스트 상자가 필요합니다. 이 이름은 employee 테이블에 firstname, middlename, lastname의 세 컬럼으로 표시됩니다.자동 제안 텍스트 상자

나는이 코드를 시도했지만 테이블의 첫 번째 열, 즉 첫 번째 열만 표시 할 수 있습니다. 세 개의 열을 모두 연결하여 텍스트 상자에 제안하는 방법.

내 코드 :

Dim strSql As String = "select P_Firstname, P_MiddleName, P_LastName from Patient_Registration" 
     Dim dtb As New DataTable 
     Using cnn As New SqlConnection(conn) 
      cnn.Open() 
      Using dad As New SqlDataAdapter(strSql, cnn) 
       dad.Fill(dtb) 
      End Using 
      cnn.Close() 
     End Using 
     txtsearch.AutoCompleteMode = AutoCompleteMode.SuggestAppend 
     txtsearch.AutoCompleteSource = AutoCompleteSource.CustomSource 
     If dtb.Rows.Count > 0 Then 
      Dim i As Integer = 0 
      For i = 0 To (dtb.Rows.Count - 1) 
       txtsearch.AutoCompleteCustomSource.Add(dtb.Rows(i)("P_FirstName")) 
      Next 
     End If 

답변

0

사용 :

For i = 0 To (dtb.Rows.Count - 1) 
    txtsearch.AutoCompleteCustomSource.Add(dtb.Rows(i)("P_FirstName") & 
              dtb.Rows(i)("P_MiddleName") & 
              dtb.Rows(i)("P_LastName")) 
Next 

대신 :

For i = 0 To (dtb.Rows.Count - 1) 
    txtsearch.AutoCompleteCustomSource.Add(dtb.Rows(i)("P_FirstName")) 
Next 
-1
[enter image description here][1] 


    [1]: https://i.stack.imgur.com/g6TR9.png 

Showing above result. 



    enter code here 

My code is : 

[System.Web.Script.Services.ScriptMethod()] 
    [System.Web.Services.WebMethod] 
    public static List<string> GetCenter(string prefixText, int count) 
    { 
     using (SqlConnection conn = new SqlConnection()) 
     { 
      conn.ConnectionString = ConfigurationManager.AppSettings["ConnectionString"].ToString(); 
      using (SqlCommand cmd = new SqlCommand()) 
      { 
       string cmdText = "Select centername from Center_Master WHere Active=1 and centername like '%' [email protected] + '%'"; 
       cmd.Parameters.AddWithValue("@SearchText", prefixText); 

       cmdText += " order by centername "; 
       cmd.CommandText = cmdText; 
       cmd.Connection = conn; 
       conn.Open(); 
       List<string> customers = new List<string>(); 
       using (SqlDataReader sdr = cmd.ExecuteReader()) 
       { 
        while (sdr.Read()) 
        { 
         customers.Add(sdr["centername"].ToString()); 
        } 
       } 
       conn.Close(); 
       return customers; 
      } 
     } 
    } 
0
<asp:TextBox ID="ddlcenter" runat="server" Font-Size="10px" TabIndex="1" Width="150px" 
                    Style="text-transform: capitalize;" 
                    placeholder="Type Center Name/Code" autocomplete="off"></asp:TextBox> 
                   <cc1:AutoCompleteExtender ServiceMethod="GetCenter" MinimumPrefixLength="2" CompletionInterval="100" 
                    EnableCaching="false" CompletionSetCount="10" TargetControlID="ddlcenter" UseContextKey="true" 
                    ID="AutoCompleteExtender1" runat="server" FirstRowSelected="false" CompletionListCssClass="completionList" 
                    CompletionListHighlightedItemCssClass="itemHighlighted" CompletionListItemCssClass="listItem"> 
                   </cc1:AutoCompleteExtender>