Good Day
I am a total novice and trying to use autocomplete to display selected results in separate textboxes but I am totally lost.
I need to capture the Full_Name and ID in the separate textboxes
here is my current files
asp file:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeFile="SearchTest.aspx.cs" Inherits="SearchTest" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<div>
<div class="ui-widget">
<label for="TextBoxSearch">
Search Person:
</label>
<asp:TextBox ID="TextBoxSearch" runat="server" />
</div>
</div>
<script src="js/jquery-1.8.3.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery-ui-1.9.2.custom.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/jquery-ui.css" />
<script type="text/javascript">
$(function() {
var PersonDetails = [ <%= PersonDetails %> ];
$("#<%= TextBoxSearch.ClientID %>").autocomplete({
minLength: 3,
source: PersonDetails
});
});
</script>
<asp:TextBox ID="TextBoxFullName" runat="Server" ReadOnly="true" />
<br />
<asp:TextBox ID="TextBoxPersonID" runat="server" ReadOnly="true" />
</asp:Content>
-------------------------------------------------------------
Code Behind:
public partial class SearchTest : System.Web.UI.Page
{
public string PersonDetails = "";
protected void Page_Load(object sender, EventArgs e)
{
string queryString = "Select CONCAT(First_Name, ' ' ,Surname) AS Full_Name, id AS PersonId [People] ORDER BY Full_Name";
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Scheduler"].ConnectionString))
{
using (SqlCommand command = new SqlCommand(queryString, connection))
{
connection.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
if (string.IsNullOrEmpty(PersonDetails))
{
PersonDetails += "\"" + reader["Full_Name"].ToString() + "\"";
}
else
{
PersonDetails += ", \"" + reader["Full_Name"].ToString() + "\"";
}
}
}
}
}
}
}