Alternate use of AutoComplete Extender AJAX
For searching what we basically need is name and id behind it.
so for that we must have a
searcher :textbox(txtSearch)
id holder when search complete:hiddenfield(hfCustomerId)
Htmil Source Side
<script type = "text/javascript">
function ClientItemSelected(sender, e) {
$get("<%=hfCustomerId.ClientID %>").value = e.get_value();
}
</script>
Search by Client:
<asp:HiddenField ID="hfCustomerId" runat="server" />
<asp:TextBox ID="txtSearch" runat="server" Width="200"></asp:TextBox>
<asp:AutoCompleteExtender ID="AutoCompleteExtender2" runat="server"
BehaviorID="AutoCompleteEx" CompletionInterval="100"
CompletionListCssClass="completionList"
CompletionListHighlightedItemCssClass="itemHighlighted"
CompletionListItemCssClass="listItem" CompletionSetCount="20" OnClientItemSelected="ClientItemSelected"
DelimiterCharacters=";, :" EnableCaching="true" MinimumPrefixLength="1"
ServiceMethod="GetClientList" ShowOnlyCurrentWordInCompletionListItem="true"
TargetControlID="txtSearch" UseContextKey="True">
</asp:AutoCompleteExtender>
Code Behind
Web Method to process autocomplete with textbox
Instead this (used for singal value)
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ALPHAconnString"]);
SqlCommand cmd = new SqlCommand("SELECT distinct [Company_Name],Client_id FROM Client where Company_Name like '" + prefixText + "%' ", con);
if (con.State == ConnectionState.Closed)
con.Open();
cmd.CommandType = CommandType.Text;
SqlDataReader dr = cmd.ExecuteReader();
while (dr.HasRows)
{
while (dr.Read())
{
string item = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dr["Company_Name"].ToString(), dr["Client_id"].ToString());
items.Add(item);
//items.Add(dr.GetValue(0).ToString());
}
dr.NextResult();
}
return items.ToArray();
Use this(to hold two value)
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ALPHAconnString"]);
SqlCommand cmd = new SqlCommand("SELECT distinct
[Company_Name],Client_id FROM Client where Company_Name like '" +
prefixText + "%' ", con);
if (con.State == ConnectionState.Closed)
con.Open();
cmd.CommandType = CommandType.Text;
SqlDataReader dr = cmd.ExecuteReader();
while (dr.HasRows)
{
while (dr.Read())
{
string item =
AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dr["Company_Name"].ToString(),
dr["Client_id"].ToString());
items.Add(item);
//items.Add(dr.GetValue(0).ToString());
}
dr.NextResult();
}
return items.ToArray();
after searching from textbox ,on any button Click
string clientid= Request.Form[hfCustomerId.UniqueID];
