TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
sam
NA
202
0
Autocomplete from database
Aug 15 2010 10:35 PM
Hi..
I implement an autocomplete texttbox using following code and it works fine :
[code]
<pre lang="xml"><%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AutoComplete2._Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string[] GetCompletionList(string prefixText, int count)
{
return "this is sample text".Split();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
ServiceMethod="GetCompletionList"
CompletionInterval="500"
ServicePath="" TargetControlID="TextBox1"
EnableCaching="true"
CompletionSetCount="20"
DelimiterCharacters=";, :"
UseContextKey="True">
</asp:AutoCompleteExtender>
<br />
</div>
</form>
</body>
</html></pre>
[/code]
I want the autocomplete to read from database. And i tried used following code in above script,but it doesn't work and shows some error
in "SqlConnection oConn = new SqlConnection(connect);" part:
[code]
<script>
public string[] GetCompanyName(string prefixText, int count)
{
string sql = "Select * from Table1 Where Company_Name like '" + prefixText + "%" + "'";
string connect = ConfigurationManager.AppSettings["Conn"];
SqlConnection oConn = new SqlConnection(connect);
SqlDataAdapter da = new SqlDataAdapter(sql, oConn);
da.SelectCommand.Parameters.Add(@prefixText, SqlDbType.NVarChar, 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["Company_Name"].ToString(), i);
i++;
}
return items;
}
</script>
[/code]
could anyone tell me where's the wrong?Is my code above correct?
Reply
Answers (
2
)
can’t get generated controls through AJAX response
about import panorma pictures in asp.net