我想要一个自动建议文本框,在输入特定字母后会显示员工姓名。该名称在employee表中以三列显示,即firstname,middlename,lastname。
我为此尝试了一个代码,但它只能显示表中的一列,即firstname。 如何连接所有三列,以便在文本框中建议它们。
我的代码:
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 :(得分: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 :(得分: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>
答案 2 :(得分:-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;
}
}
}