Source Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.AutoExtender
{
font-family: Verdana, Helvetica, sans-serif;
font-size: .8em;
font-weight: normal;
border: solid 1px #006699;
line-height: 20px;
padding: 10px;
background-color: White;
margin-left: 10px;
}
.AutoExtenderList
{
border-bottom: dotted 1px #006699;
cursor: pointer;
color: Maroon;
}
.AutoExtenderHighlight
{
color: White;
background-color: #006699;
cursor: pointer;
}
#divwidth
{
width: 150px !important;
}
#divwidth div
{
width: 150px !important;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/Service.svc" />
</Services>
</asp:ScriptManager>
<cc1:AutoCompleteExtender runat="server" ID="AutoComplete1" BehaviorID="autoComplete"
TargetControlID="TextBox1" ServicePath="Service.svc" ServiceMethod="GetEmpInfoWith_WCF"
MinimumPrefixLength="1" CompletionInterval="10" EnableCaching="true" CompletionSetCount="12"
CompletionListCssClass="AutoExtender" CompletionListItemCssClass="AutoExtenderList"
CompletionListHighlightedItemCssClass="AutoExtenderHighlight" CompletionListElementID="divwidth" />
<div id="divwidth">
</div>
<center>
EmpName
<asp:TextBox ID="TextBox1" Width="150px" runat="server" />
</center>
<br />
</div>
</form>
</body>
</html>
Service.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using System.Data;
using System.Data.SqlClient;
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service
{
[OperationContract]
public void DoWork()
{
// Add your operation implementation here
return;
}
[OperationContract]
public string[] GetEmpInfoWith_WCF(string prefixText)
{
SqlConnection con = new SqlConnection(@"server=SWASH-DBS\SWASHSQLINT;database=kenCampus;uid=ken;pwd=kc@2011");
string sql = "Select LedgerName from Rakesh Where LedgerName like @LedgerName";
SqlDataAdapter da = new SqlDataAdapter(sql, con);
da.SelectCommand.Parameters.Add("@LedgerName", SqlDbType.VarChar, 50).Value = prefixText + "%";
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
string[] items = new string[dt.Rows.Count];
int i = 0;
foreach (DataRow dr in dt.Rows)
{
items.SetValue(dr["LedgerName"].ToString(), i);
i++;
}
return items;
}
else
{
string[] items = new string[1];
items.SetValue("No EmpName Found", 0);
return items;
}
}
}
// Add more operations here and mark them with [OperationContract]
No comments:
Post a Comment