本文介绍了自动完成控制不起作用..这是我的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hi! dear frnds i want to make auto complete text box and my code is not working plz tell what is the problem in this code
<asp:TextBox ID="txtAreaName" runat="server" CssClass="txtArea" placeholder="Enter Area to Search Dealers" Height="34px" Width="259px"></asp:TextBox>
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" ServiceMethod="GetArea" MinimumPrefixLength="2"
runat="server" CompletionInterval="100" EnableCaching="true" CompletionSetCount="10" TargetControlID="txtAreaName" FirstRowSelected="true"></asp:AutoCompleteExtender>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OracleClient;
using System.Data;
using System.Configuration;
using System.Web.Services;
using System.Web.Services.Protocols;
namespace OnlinePropertyDealer.MasterPage
{
public partial class OnlineDealers : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public string[] GetArea(string prefixText, int count)
//[System.Web.Script.Services.ScriptMethod()]
//[System.Web.Services.WebMethod]
//public static List<string> GetArea(string prefixText)
{
List<string> AreaNames = new List<string>();
using (OracleConnection con = new OracleConnection())
{
con.ConnectionString = ConfigurationManager
.ConnectionStrings["conStr"].ConnectionString;
using (OracleCommand cmd = new OracleCommand())
{
cmd.CommandText = "select area_namr from area_table where " +
"area_name like @SearchText + '%'";
cmd.Parameters.AddWithValue("@SearchText", prefixText);
cmd.Connection = con;
con.Open();
using (OracleDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
AreaNames.Add(sdr["area_name"].ToString());
}
}
con.Close();
return AreaNames.ToArray();
}
}
推荐答案
Collapse | Copy Code
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string[] GetArea(string prefixText, int count)
所以你想从前端使用的任何后端Web方法可能是ajax,jquery ......
它需要静态网络方法
获取更多信息
[]
这篇关于自动完成控制不起作用..这是我的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!