Hey, I need your help.
I need to create a GridView, using C# and ASP.Net, that populates from a TextBox (AutoComplete TextBox) that autocompletes (autocomplete extender) from database data.
I have tried this demo without success.
https://www.aspsnippets.com/demos/2899/
Can you help me?
Thanks
<%@ Page Title=""
Language="C#"
MasterPageFile="MaP.master"
AutoEventWireup="true"
CodeFile="Default.aspx.cs"
Inherits="_Default"
EnableEventValidation="false"
MaintainScrollPositionOnPostback="true" %>
<%@ MasterType VirtualPath="MaP.master" %>
<%@ Register TagPrefix="asp" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
<script type="text/javascript">
$(function () {
$(".Country").autocomplete({
source: function (request, response) {
$.ajax({
url: 'Default.aspx/GetCountries',
data: "{ 'prefix': '" + request.term + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
response($.map(data.d, function (item) {
return {
label: item.split('-')[0],
val: item.split('-')[1]
}
}))
},
error: function (response) {
alert(response.responseText);
},
failure: function (response) {
alert(response.responseText);
}
});
},
select: function (e, i) {
$(this).parent().find("input[type=hidden]").val(i.item.val);
},
minLength: 1
}).focus(function () {
$(this).autocomplete("search");
});
});
</script>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.0.min.js" type="text/javascript"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.2/jquery-ui.min.js" type="text/javascript"></script>
<link href="https://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.2/themes/blitzer/jquery-ui.css" rel="Stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="Server">
<asp:TextBox ID="txtCountry" runat="server" CssClass="Country" />
<asp:HiddenField ID="hfCountry" runat="server" />
</asp:Content>