1

我想要一个自动建议文本框,在输入特定字母后显示员工姓名。姓名存在于雇员表中的三列中,即名字、中间名、姓氏。

我为此尝试了一个代码,但它只能显示表格的一列,即名字。如何连接所有三列,以便在文本框中建议它们。

我的代码:

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
4

3 回答 3

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
于 2012-11-03T08:42:01.830 回答
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>
于 2017-04-29T06:04:32.680 回答
-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 '%' +@SearchText  + '%'";
                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;
            }
        }
    }
于 2017-04-29T05:57:43.500 回答