如何使用AutoCompleteExtender

时间:2011-07-26 00:26:20

标签: asp.net

如何使用AutoCompleteExtender。我在Windows服务器上使用ASP.NET 4.0。我想从数据库填充一些数据。

1 个答案:

答案 0 :(得分:1)

我建议您使用ajax工具包:http://www.asp.net/ajax/ajaxcontroltoolkit/samples/

为了能够首先将dll添加到bin文件夹中。

这就是我用的例子(你可以编写自己的css类)

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>


    <ajaxToolkit:AutoCompleteExtender runat="server" BehaviorID="AutoCompleteEx" ID="AutoExtend1"
            TargetControlID="txtPokemonNameSearch" ServicePath="AutoCompleteName.asmx" ServiceMethod="GetCompletionListPokemonName"
            MinimumPrefixLength="1" CompletionInterval="500" EnableCaching="true" CompletionSetCount="25"
            CompletionListCssClass="AutoExtender" CompletionListItemCssClass="AutoExtenderList"
            CompletionListHighlightedItemCssClass="AutoExtenderHighlight" CompletionListElementID="DIVAutoExtender"
            DelimiterCharacters=";, :" ShowOnlyCurrentWordInCompletionListItem="true">
            <Animations>
                <OnShow>
                    <Sequence>
                        <OpacityAction Opacity="0" />
                        <HideAction Visible="true" />
                        <ScriptAction Script="
                            // Cache the size and setup the initial size
                            var behavior = $find('AutoCompleteEx');
                            if (!behavior._height) {
                                var target = behavior.get_completionList();
                                behavior._height = target.offsetHeight - 2;
                                target.style.height = '0px';
                            }" />
                                                   <Parallel Duration=".4">
                            <FadeIn />
                            <Length PropertyKey="height" StartValue="0" EndValueScript="$find('AutoCompleteEx')._height" />
                        </Parallel>
                    </Sequence>
                </OnShow>
                <OnHide>               
                    <Parallel Duration=".4">
                        <FadeOut />
                        <Length PropertyKey="height" StartValueScript="$find('AutoCompleteEx')._height" EndValue="0" />
                    </Parallel>
                </OnHide>
            </Animations>
        </ajaxToolkit:AutoCompleteExtender>