如何在文本框中显示结果?

时间:2012-03-29 05:39:23

标签: asp.net

在我的表单中,有一个用于显示productname的文本框。我想在文本框中输入l时这样,它显示所有记录从l开始作为建议。 我编写查询并执行相同的选择,从table中选择productname,如'l%'。在asp.net文本框中不包含onblur事件或焦点事件。在哪个事件中,我应该执行query.I试过textbox_textchange event.But它不是在努力。

3 个答案:

答案 0 :(得分:2)

更好地使用AjaxToolkit的AutoComplete控件。它的工作方式与您尝试的相似。请在此处查看演示:AutoComplete Demonstration

<ajaxToolkit:AutoCompleteExtender 
runat="server" 
ID="autoComplete1" 
TargetControlID="myTextBox"
ServiceMethod="GetCompletionList"
ServicePath="AutoComplete.asmx"
MinimumPrefixLength="2" 
CompletionInterval="1000"
EnableCaching="true"
CompletionSetCount="20" 
CompletionListCssClass="autocomplete_completionListElement" 
CompletionListItemCssClass="autocomplete_listItem" 
CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
DelimiterCharacters=";, :"
ShowOnlyCurrentWordInCompletionListItem="true">
    <Animations>
        <OnShow> ... </OnShow>
        <OnHide> ... </OnHide>
    </Animations>

答案 1 :(得分:0)

默认的asp.net文本框无法做到这一点。

尝试阅读有关JQuery,ajax和自动完成的内容。 您可以使用以下内容:http://www.aspsnippets.com/Articles/Using-jQuery-AutoComplete-Plugin-in-ASP.Net.aspx

答案 2 :(得分:0)

  TextBox1.Attributes.Add("onkeypress", "return clickButton(event,'" + Button1.ClientID + "')");

后面的代码生成以下代码:

<input name="TextBox1" type="text" id="TextBox1" onkeypress="return clickButton(event,'Button1')"  />

这会导致在TextBox1中按下回车键时单击Web控件Button1。 您可以根据需要自定义此示例。