How to use ListSearchExtender in asp.net ajax

ListSearchExtender
ListSearchExtender is an asp.net ajax control toolkit's extender control. ListSearchExtender control can be extend asp.net ListBox and DropDownList web server controls. ListSearchExtender control allow us to search for items in an extended ListBox or DropDownList server control by typing. ListSearchExtender control provide an incremental search within the ListBox based on what has been typed so far.

ListSearchExtender control have the following properties those are TargetControlID, PromptText, PromptCssClass, PromptPosition, QueryPattern, IsSorted, QueryTimeout, Animations, OnShow, OnShowBehavior, OnHide, OnHideBehavior and raiseImmediateOnChange.

ListSearchExtender control's TargetControlID specify the asp.net ListBox or DropDownList control which we want to provide items search facility. PromptText property set a message to display when the target control get focus. PromptCssClass allow us to design prompt message using css style. PromptPosition property set the position of prompt message in target ListBox or DropDownList control. PromptPosition property value can be Top or Bottom and default value is Top.

QueryPattern property specify how the typed characters should be used in the search query. default query pattern is StartsWith that means results starts with the typed word. QueryPattern property another value is Contains.

QueryTimeout property indicate whether the search query should be reset after the timeout if no match is found. default value is 0 that means no auto reset behavior. IsSorted property indicate if items added to the list are expected to be sorted.

Animations property allow us to apply generic animations for the ListSearchExtender. OnShow ensure animation will be played each time the prompt is displayed and OnHide ensure animation will be played each time prompt message is hidden.

raiseImmediateOnChange property indicate whether an OnChange event should be fired as soon as the selected element is changed, when the list loses focus or user hits enter.

ListSearchExtender control have the following methods those are initialize(), dipose(), OnShow() and OnHide(). OnShow() method play the OnShow animation and OnHide() method play the OnHide animation.
UsingListSearchExtender.aspx

<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<!DOCTYPE html>

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack)
        {
            string[] colorList = Enum.GetNames(typeof(KnownColor));
            ListBox1.DataSource = colorList;
            ListBox1.DataBind();
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Ajax ListSearchExtender - How to use ListSearchExtender in asp.net ajax</title>
    <style type="text/css">
        .PromptCSS
        {
            color:DodgerBlue;
            font-size:large;
            font-style:italic;
            font-weight:bold;
            background-color:AliceBlue;
            height:25px;
            }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:SeaGreen; font-style:italic;">Ajax Control Toolkit Example: Using ListSearchExtender</h2>
        <hr width="550" align="left" color="LawnGreen" />
        <asp:ScriptManager 
            ID="ScriptManager1"
            runat="server"
            >
        </asp:ScriptManager>
        <cc1:ListSearchExtender 
            ID="ListSearchExtender1"
            runat="server"
            TargetControlID="ListBox1"
            PromptCssClass="PromptCSS"
            >
        </cc1:ListSearchExtender>
        <br /><br />
        <asp:ListBox 
            ID="ListBox1"
            runat="server"
            BackColor="Pink"
            ForeColor="DeepPink"
            Font-Size="Medium"
            Font-Bold="true"
            Height="250"
            >
        </asp:ListBox>
    </div>
    </form>
</body>
</html>
Related asp.net ajax examples