紧急...自动完成扩展器不起作用 [英] Urgent...AutoComplete Extender not working
问题描述
自动完成扩展器在Visual Studio 2008中无法正常工作.我正在使用以下代码:-
< asp:AutoCompleteExtender ID ="TextBox1_AutoCompleteExtender" runat =服务器" CompletionInterval ="0"
CompletionListElementID ="search" CompletionSetCount ="12" EnableCaching ="true"
MinimumPrefixLength ="1" ServiceMethod ="GetEmpID" ServicePath =〜/WebService1.asmx"
ShowOnlyCurrentWordInCompletionListItem ="true" TargetControlID ="TextBox1">
下面是Web服务代码:
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
公共字符串[] GetEmpID(字符串prefixText)
{
SqlConnection con =新的SqlConnection("server = sushma-pc; user id = sa; password = secure2011; database = dbase");
DataSet ds = new DataSet();
DataTable dt = new DataTable();
SqlCommand cmd =新的SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText =从Tbl_EmpDetails中选择不同的EmpID,其中EmpID如@myParameter";
cmd.Parameters.AddWithValue("@ myParameter",%" + prefixText +%");
试试
{
con.Open();
cmd.ExecuteNonQuery();
SqlDataAdapter da =新的SqlDataAdapter(cmd);
da.Fill(ds);
}
赶上
{
}
终于
{
con.Close();
}
dt = ds.Tables [0];
List< string> EmpID =新列表< string>();
字符串dbValues;
foreach(dt.Rows中的DataRow行)
{
dbValues = row ["EmpID"].ToString();
dbValues = dbValues.ToLower();
EmpID.Add(dbValues);
}
返回EmpID.ToArray();
}
}
尽管列表不在文本框中,但我没有出现任何错误.
请分享您对相同的想法
Hi,
Auto Complete extender is not working properly in visual studio 2008.I am using the following code :-
<asp:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server" CompletionInterval="0"
CompletionListElementID="search" CompletionSetCount="12" EnableCaching="true"
MinimumPrefixLength="1" ServiceMethod="GetEmpID" ServicePath="~/WebService1.asmx"
ShowOnlyCurrentWordInCompletionListItem="true" TargetControlID="TextBox1" >
below is the webservice code:
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public string[] GetEmpID(string prefixText)
{
SqlConnection con = new SqlConnection("server=sushma-pc;user id=sa;password=secure2011;database=dbase");
DataSet ds = new DataSet();
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select Distinct EmpID from Tbl_EmpDetails where EmpID like @myParameter";
cmd.Parameters.AddWithValue("@myParameter", "%" + prefixText + "%");
try
{
con.Open();
cmd.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
}
catch
{
}
finally
{
con.Close();
}
dt = ds.Tables[0];
List<string> EmpID = new List<string>();
String dbValues;
foreach (DataRow row in dt.Rows)
{
dbValues = row["EmpID"].ToString();
dbValues = dbValues.ToLower();
EmpID.Add(dbValues);
}
return EmpID.ToArray();
}
}
I am not getting any kind of error though the list is not coming in the textbox.
Kindly share your ideas regarding the same
推荐答案
乍一看,尝试更改参数名称.
公共字符串[] GetEmpID(字符串 contextKey )
At first glance, try changing the parameter name.
public string[] GetEmpID(string contextKey)
这篇关于紧急...自动完成扩展器不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!