Jquery (.aspx page)
<script type="text/javascript" language="javascript">
$(document).ready(function () {
function extractLast(q) { return q; }
$("#autocomplete").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json",
data: { q: request.q },
dataType: "json",
url: "Playermanagment.aspx?q=" + $('#autocomplete').val(),
success: function (msg) {
msg = msg.Data.split(',');
response(msg);
//response($.parseJSON(msg.d).Records);
},
error: function (Err) {
//alert(msg.status + ' ' + msg.statusText);
}
})
},
minLength: 3,
search: function () {
var q = extractLast(this.value)
if (q.length < 1) {
return false;
}
}
});
});
</script>
Code for text box(.aspx page)
<asp:Label ID="lblEvent" runat="server" Text="Enter the Name of Player" meta:resourcekey="txtlblEventResource1"></asp:Label>
<input type="text" runat="server" id="autocomplete" class="autosuggest" meta:resourcekey="autocompleteResource1" />
<asp:Button ID="BtnGo1" runat="server" Text="Go" meta:resourcekey="BtnGo1Resource2" />
code behind
public partial class Playermanagment : BaseClass
{
if (Request.QueryString["q"] != null)
{
string strJSON = string.Empty;
try
{
string prefix = Request.QueryString["q"];
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SELECT Player_Name FROM Profiles WHERE Player_Name LIKE '%" + prefix + "%' ";
cmd.Connection = con;
StringBuilder sb = new StringBuilder();
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
sb.Append(dr["Player_Name"].ToString() + ",");
}
con.Close();
strJSON = sb.ToString().Trim(',');
}
catch (Exception ex)
{
}
finally
{
Response.ClearContent();
Response.ContentType = "application/json";
strJSON = "{\"Data\":\" " + strJSON + "\"}";
Response.Write(strJSON);
Response.End();
}
}
}
}
}