Wednesday, July 8, 2009

Autocomplete webservice

table
country Name nvarchar(50)
country_code int

webserviceusing

using System.Collections.Generic;
using System.Web.Services;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class AutoComplete : WebService
{
public AutoComplete()
{
}

[WebMethod]
public string[] GetCountryInfo(string prefixText)
{
int count = 10;
string sql = "Select * from ECM_ITEM_MASTER Where ITEM_NAME like @prefixText";
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbEcommerceConnectionString"].ConnectionString);
SqlDataAdapter da = new SqlDataAdapter(sql, con);
da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText + "%";
DataTable dt = new DataTable();
da.Fill(dt);
string[] items = new string[dt.Rows.Count];
int i = 0;
foreach (DataRow dr in dt.Rows)
{
items.SetValue(dr["ITEM_NAME"].ToString(), i);
i++;
}
return items;
}
}

default.aspx
...............defalut.aspx.........................
<asp:TextBox ID="TextBox1" runat="server" autocomplete="off" Width="300px"></asp:TextBox>

<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" BehaviorID="AutoCompleteEx"
runat="server" EnableCaching="true"
CompletionInterval="200" CompletionListCssClass="autocompleteplus_completionListElement"
CompletionListItemCssClass="autocompleteplus_listItem" CompletionListHighlightedItemCssClass="autocompleteplus_highlightedListItem"
DelimiterCharacters=";, :"
MinimumPrefixLength="1" ServiceMethod="GetCountryInfo"
ServicePath="AutoComplete.asmx"
TargetControlID="TextBox1">


<Animations>


<OnShow>

<Sequence>
<%-- Make the completion list transparent and then show it --%>

<OpacityAction Opacity="0" />

<HideAction Visible="true" />

<%--Cache the original size of the completion list the first time the animation is played and then set it to zero --%>
<ScriptAction Script=" // Cache the size and setup the initial size var behavior
= $find('AutoCompleteEx'); if (!behavior._height) { var target = behavior.get_completionList();
behavior._height = target.offsetHeight - 2; target.style.height = '0px'; }" />
<%-- Expand from 0px to the appropriate size while fading in --%>

<Parallel Duration=".4">


<FadeIn />

<Length PropertyKey="height"
StartValue="0" EndValueScript="$find('AutoCompleteEx')._height" /> </Parallel>
</Sequence> </OnShow> <OnHide>
<%-- Collapse down to 0px and fade out --%>
<Parallel Duration=".4">


<FadeOut />


<Length PropertyKey="height"
StartValueScript="$find('AutoCompleteEx')._height" EndValue="0" />

</Parallel>
</OnHide> </Animations> </cc1:AutoCompleteExtender>

No comments:

Post a Comment

http://blogsiteslist.com