my source code
<%@ Page Language="C#" MasterPageFile="~/MasterPage/Employe.master" AutoEventWireup="true" CodeFile="Attendance.aspx.cs" Inherits="Employee_Attendance" Title="Untitled Page" %>
.style1
{
width: 100%;
}
$(function () {
$("[id*=ctl00_ContentReport_TextBox2]").autocomplete({
source: function (request, response) {
$.ajax({
url: 'Attendance.aspx/GetAutoCompleteData',
data: "{ 'prefix': '" + request.term + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
if (data.d.length > 0) {
response($.map(data.d, function (item) {
return {
label: item.split('-')[0],
val: item.split('-')[1]
};
}))
} else {
response([{ label: 'No results found.', val: -1}]);
}
}
});
},
select: function (e, u) {
if (u.item.val == -1) {
return false;
}
}
});
});
$(function () {
$("[id*=ctl00_ContentReport_TextBox1]").autocomplete({
source: function (request, response) {
$.ajax({
url: 'Attendance.aspx/CompleteData',
data: "{ 'prefix': '" + request.term + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
if (data.d.length > 0) {
response($.map(data.d, function (item) {
return {
label: item.split('-')[0],
val: item.split('-')[1]
};
}))
} else {
response([{ label: 'No results found.', val: -1}]);
}
}
});
},
select: function (e, u) {
if (u.item.val == -1) {
return false;
}
}
});
});
ImageUrl="~/Images/enter_button.png" Width="69px" /> | |
contentplaceholderid="ContentPlaceHolder1">
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.SqlClient;
using System.Drawing;
using System.Web.Services;
using System.Text;
public partial class Employee_Attendance : System.Web.UI.Page
{
//string constr = ConfigurationManager.AppSettings["s"].ToString();
//[System.Web.Services.WebMethod]
//[System.Web.Script.Services.ScriptMethod()]
protected void Page_Load(object sender, EventArgs e)
{
}
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod()]
public static string[] CompleteData(string prefix)
{
string constr = ConfigurationManager.AppSettings["s"].ToString();
List resultt = new List();
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("select DISTINCT Name from EmpReg where " + "Name like @SearchText + '%'", con))
{
cmd.Parameters.AddWithValue("@SearchText", prefix);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
resultt.Add(dr["Name"].ToString());
}
con.Close();
}
return resultt.ToArray();
}
}
public static string[] GetAutoCompleteData(string prefix)
{
string constr = ConfigurationManager.AppSettings["s"].ToString();
List result = new List();
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("select DISTINCT Section from EmpReg where " + "Section like @SearchText + '%'", con))
{
cmd.Parameters.AddWithValue("@SearchText", prefix);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
result.Add(dr["Section"].ToString());
}
con.Close();
}
return result.ToArray();
}
}
}
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Lakshmanan Sethu SankaranarayanPosted May 15, 2014, 2:17 AM