auto completeextender
DESCRIPTION
Elemento de asp.netTRANSCRIPT
<script type="text/javascript">
function ace1_itemSelected(sender, e) { var ace1Value = $get('<%= HiddenIDValor.ClientID%>'); ace1Value.value = e.get_value(); }
</script> <asp:HiddenField ID="HiddenIDValor" runat="server" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:TextBox ID="txt_BuscarPersonas" runat="server" AutoComplete="off"></asp:TextBox>
<asp:AutoCompleteExtender ID="AutoComple_Persona" TargetControlID="txt_BuscarPersonas" ServiceMethod="BuscarPersonas" MinimumPrefixLength="3" OnClientItemSelected="ace1_itemSelected" FirstRowSelected="true" CompletionInterval="0" runat="server"></asp:AutoCompleteExtender>
<asp:Button ID="Button1" runat="server" Text="Button" />
<System.Web.Script.Services.ScriptMethod(), System.Web.Services.WebMethod()> _ Public Shared Function BuscarPersonas(ByVal prefixText As String, ByVal count As Integer)
Dim vpersonas As New dt_persona
Dim lista = (From p In vpersonas.listarPersona()Where (p.Nombres.ToUpper & " " & p.Apellidos.ToUpper).StartsWith(prefixText.ToUpper)Select AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(p.Nombres.ToUpper & " " & p.Apellidos.ToUpper, p.ID)).Take(count).ToArray
Return lista
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.ClickLabel1.Text = HiddenIDValor.ValueEnd Sub
[System.Web.Services.WebMethod] public static string[] GetSuggestions(string prefixText, int count) { MyDatabaseDataContext db = new MyDatabaseDataContext(); List<Product> products = db.Products .Where( m => m.Title.StartsWith(prefixText) ) .OrderBy( m => m.Title ) .Take(count) .ToList(); return products .Select( m => AutoCompleteExtender.CreateAutoCompleteItem( m.Title, m.Id.ToString())) .ToArray(); }
protected void btnSubmit_Click(object sender, EventArgs e) { lblSelectedProductTitle.Text = txtProductTitle.Text; lblSelectedProductId.Text = ace1Value.Value; }
</script><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"> <title>AutoComplete Page Method</title> <script type="text/javascript">
function ace1_itemSelected(sender, e) { var ace1Value = $get('<%= ace1Value.ClientID %>'); ace1Value.value = e.get_value(); } </script>
<asp:Label id="lblProductTitle" Text="Product:" AssociatedControlID="txtProductTitle" Runat="server" /> <asp:TextBox id="txtProductTitle" AutoComplete="off" Runat="server" /> <ajax:AutoCompleteExtender id="ace1" TargetControlID="txtProductTitle" ServiceMethod="GetSuggestions" MinimumPrefixLength="1" OnClientItemSelected="ace1_itemSelected" FirstRowSelected="true" runat="server" /> <asp:HiddenField id="ace1Value" Runat="server" /> <asp:Button id="btnSubmit" Text="Submit" OnClick="btnSubmit_Click" Runat="server" />
<br /><br />
Title: <asp:Label id="lblSelectedProductTitle" runat="server" />
<br /><br /> Primary Key: <asp:Label id="lblSelectedProductId" runat="server" />
</div> </form></body></html>