ASP.NET中的自动完成扩展器问题 [英] Autocomplete Extender problem in asp.net
问题描述
我正在使用asp.net 3.5,visualstudio 2008,sqlserver2008和webservice
在我的项目中,自动完成扩展程序"用于使用入场号进入我们的数据库,它存储在121010001/002
121020001/003
121020002/002
121010002/001
111020002/001
111020001/003
111010001/001的格式.但我已经采用这种格式进行自动填充了
60505000.5
40340000.333333336
60510001
121010002
111020002
37006667
111010001
我不知道问题,请帮我解决问题.
在存储过程中,get记录的格式正确(即121010001/002
121020001/003
121020002/002
121010002/001
111020002/001
111020001/003
111010001/001)
我在service.asmx中使用了webservice,方法是在service.cs中编写的,我只是使用ajax autocompleteExtender控件调用了aspx页面,而servicepath是service.asmx和servicemethod在service.cs页面中编写了webmethod,以调用该函数.
示例代码在这里
Hi,
i am using asp.net 3.5 ,visualstudio 2008 ,sqlserver2008 using webservice
In my project Autocomplete extender for using admission no. get in our database it was stored in 121010001/002
121020001/003
121020002/002
121010002/001
111020002/001
111020001/003
111010001/001 in this format. but i have get in autocomplete was in this format
60505000.5
40340000.333333336
60510001
121010002
111020002
37006667
111010001
i don''t know the problem pls help me to correct the problem.
In stored procedure get records are correct format (that is 121010001/002
121020001/003
121020002/002
121010002/001
111020002/001
111020001/003
111010001/001)
i have use webservice in service.asmx and the methods are written in service.cs i am just call aspx page with ajax autocompleteExtender control and servicepath was service.asmx and servicemethod are written webmethod in service.cs page to call th function.
sample code here
<asp:TextBox ID="txtAdmisssionNo" runat="server" Onkeypress="return allownumbers(event)" MaxLength="15"></asp:TextBox>
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtAdmisssionNo"
ServicePath="~/Service.asmx" MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1"
CompletionInterval="100" ServiceMethod="getAdmissionNo" OnClientPopulating="ShowProcessImage"
OnClientPopulated="HideProcessImage" >
</asp:AutoCompleteExtender>
service.cs页面代码在这里
service.cs page code here
[WebMethod]
public List<string> getAdmissionNo(string prefixText)
{
SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.AppSettings["MyCon"].ToString());
sqlConnection.Open();
//SqlCommand sqlCommand = new SqlCommand("select ISNULL(AdmissionNo,ApplicationID)AdmissionNo from OA_ADM_tblAdmission_AdmissionDetails where AdmissionNo like @Name+'%' OR ApplicationID like @Name+'%' ", sqlConnection);
SqlCommand sqlCommand = new SqlCommand("select ISNULL(AdmissionNo,ApplicationID)AdmissionNo from OA_ADM_tblAdmission_AdmissionDetails where AdmissionNo like @Name+'%'", sqlConnection);
sqlCommand.Parameters.AddWithValue("@Name", prefixText);
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
DataTable dt = new DataTable();
sqlDataAdapter.Fill(dt);
List<string> AdmissionNos = new List<string>();
for (int i = 0; i < dt.Rows.Count; i++)
{
AdmissionNos.Add(dt.Rows[i]["AdmissionNo"].ToString());
}
return AdmissionNos;
}
推荐答案
为此,您的Web服务应返回除法的值
更改您的代码链接
For this your web service should return the divided values
change your code link this
for (int i = 0; i < dt.Rows.Count; i++)
{
string s=dt.Rows[i]["AdmissionNo"].ToString();
AdmissionNos.Add( Convert.ToDouble(s.Split('/')[0]) / Convert.ToDouble(s.Split('/')[1]));
}
希望这会给您一个IDEA.
Hope this will give you an IDEA.
AdmissionNos.Add(dt.Rows[i][AdmissionNo].ToString());
更改为
change to
AdmissionNos.Add("\""+dt.Rows[i]["AdmissionNo"].ToString()+ "\"");
或
or
AdmissionNos.Add("''" + dt.Rows[i]["AdmissionNo"].ToString() + "''");
这篇关于ASP.NET中的自动完成扩展器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!