I implement an autocomplete texttbox using following code and it works fine :
[code]
<%@ 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>[/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]
[/code]
could anyone tell me where's the wrong?Is my code above correct?
samPosted Aug 16, 2010, 12:13 AM
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AutoComplete2._Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%@ Import Namespace = "System.Data" %>
<%@ Import Namespace = "System.Data.SqlClient" %>
samPosted Aug 16, 2010, 12:11 AM
I added following code on aspx file:
And this code on cs file:
using System.Data.SqlClient;it works fine,it reads and suggests from database.