有人可以帮助我使用C#在Asp.Net中创建自动完成文本框。 我试图从我的目标创造但不工作。
我使用Oracle 11g作为数据库。
以下是我的代码
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender ServiceMethod="GetCompletionList" MinimumPrefixLength="1" CompletionInterval="10" EnableCaching="false" CompletionSetCount="1" TargetControlID="TextBox1" ID="AutoCompleteExtender1" runat="server" FirstRowSelected="false">
</ajaxToolkit:AutoCompleteExtender>
C# Code:
[WebMethod]
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> GetCompletionList(string prefixText, int count)
{
return AutoFillProducts(prefixText);
}
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
private static List<string> AutoFillProducts(string prefixText)
{
using (OracleConnection con = new OracleConnection("DATA SOURCE=172.30.16.30:1522/PUNDEV11;PASSWORD=NCHANNEL;PERSIST SECURITY INFO=True;USER ID=NCHANNEL"))
{
using (OracleCommand com = new OracleCommand())
{
com.CommandText = "select * from thread where " + "summary like @Search + '%'";
com.Parameters.AddWithValue("@Search", prefixText);
com.Connection = con;
con.Open();
List<string> summ = new List<string>();
using (OracleDataReader sdr = com.ExecuteReader())
{
while (sdr.Read())
{
summ.Add(sdr["summary"].ToString());
}
}
con.Close();
return summ;
}
}
}