How to implement Autocomplete Extender textbox using database

Posted by Sampath1750 under ASP.NET on 4/4/2012 | Points: 10 | Views : 3531 | Status : [Member] | Replies : 3
I need implement Auto complete text box, values getting from database (Server) using Asp.Net MVC3, using javascript or jQuery. So please try help me with source.
Thanks. .




Responses

Posted by: Self-Innovator on: 4/4/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi sampath....Chek wit this
Create Design wit Ajax Enable Webiste
<form id="form1" runat="server">

<div align="center" id="ID1" runat="server" style="color: gray">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="Web Service/AutoComplete.asmx" />
</Services>
</asp:ScriptManager>
<h2 class="header2" align="Center">Person Details</h2>
<script type="text/javascript" language="javascript">
$("h2.header2").html("Background:color:Green);
</script>
<br />
<table class="table" align="center">
<tr>
<td class="td">
<asp:Label ID="EmpId" runat="server" Text="Id" CssClass="controls"></asp:Label>
</td>
<td><asp:Label ID="lblId" runat="server"></asp:Label></td>
</tr>
<tr>
<td class="td"><asp:Label ID="lblName" Text="Person Name" runat="server" CssClass="controls"></asp:Label></td>
<td>
<asp:TextBox ID="txtName" runat="server" onClick="validateName(this)"></asp:TextBox>
<cc1:AutoCompleteExtender DelimiterCharacters=";, " CompletionListCssClass="autoComplete_CompletionListElement"
CompletionListItemCssClass="autoComplete_ListItem" CompletionListHighlightedItemCssClass="autoComplete_HighLightedItem" OnClientPopulating="ShowIcon"
ID="AutoCompleteExtenderText1" MinimumPrefixLength="1" runat="server" TargetControlID="txtName"
ServiceMethod="GetNamesList" ServicePath="Web Service/AutoComplete.asmx" EnableCaching="true" CompletionInterval="1000">
</cc1:AutoCompleteExtender>
</td>
</tr>
</table>

Create a WebMethod in Web Service

[WebMethod]
public string[] GetNamesList(string prefixText, int count)
{
if (count == 0)
{
count = 10;
}
DataTable dt = GetNames(prefixText);
List<string> items = new List<string>(count);
for (int i = 0; i < dt.Rows.Count; i++)
{
string strName = dt.Rows[i][0].ToString();
items.Add(strName);
}
return items.ToArray();
}



Join Hands Change lives
Thanks & Regards
Straight Edge Society

Sampath1750, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sampath1750 on: 4/4/2012 [Member] Starter | Points: 25

Up
0
Down
Thanku for ur response, but i need this in MVC3

Sampath1750, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Self-Innovator on: 4/4/2012 [Member] Bronze | Points: 25

Up
0
Down
Sorry i diont have latest framewrk...I AM USING vs 2005

Join Hands Change lives
Thanks & Regards
Straight Edge Society

Sampath1750, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response