代码没有在asp中使用 [英] code not woking in asp
本文介绍了代码没有在asp中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
AutoCompleteStringCollection Uni = new AutoCompleteStringCollection();
Ds = Dm.ExecuteDataset("Select Distinct(University) from Course order by University");
for (int i = 0; i < Ds.Tables[0].Rows.Count; i++)
Uni.Add(Ds.Tables[0].Rows[i][0].ToString());
txtUnitversity.AutoCompleteCustomSource = Uni;
这是窗体格式代码..我必须在asp.net中使用此代码。但它会在最后显示错误行。
.AutoCompleteCustomSource。错误是:
this is window form code..i have to use this code in asp.net.but it will show error in last line.
".AutoCompleteCustomSource ".error is:
Error 1 'System.Web.UI.WebControls.TextBox' does not contain a definition for 'AutoCompleteCustomSource' and no extension method 'AutoCompleteCustomSource' accepting a first argument of type 'System.Web.UI.WebControls.TextBox' could be found (are you missing a using directive or an assembly reference?) C:\Users\PRASHANT\Desktop\OnlineIMS\create_course.aspx.cs
推荐答案
Hello Prashant,
您将无法按原样使用您的代码。而是使用 AutoCompleteExtender 。下面给出的样本
ASPX Markup
Hello Prashant,
You won''t be able to use your code as is. Instead use AutoCompleteExtender. Sample given below
ASPX Markup
<asp:ScriptManager ID="ScriptManager1" runat="server"
EnablePageMethods = "true">
</asp:ScriptManager>
<asp:TextBox ID="txtUnitversity" runat="server"></asp:TextBox>
<cc1:AutoCompleteExtender ServiceMethod="getUniversities"
MinimumPrefixLength="2" CompletionInterval="100" EnableCaching="false" CompletionSetCount="10"
TargetControlID="txtUnitversity" ID="AutoCompleteExtender1" runat="server">
</cc1:AutoCompleteExtender>
C#Code Behind
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> getUniversities(string prefixText) {
using (SqlConnection conn = new SqlConnection()) {
conn.ConnectionString = ConfigurationManager.ConnectionStrings["mycnn"].ConnectionString;
using (SqlCommand cmd = new SqlCommand()) {
cmd.CommandText = "SELECT DISTINCT(University) FROM Course ORDER BY University";
cmd.Connection = conn;
conn.Open();
List<string> lstRet = new List<string>();
using (SqlDataReader sdr = cmd.ExecuteReader()) {
while (sdr.Read()) {
lstRet.Add(sdr["University"].ToString());
}
}
conn.Close();
return lstRet;
}
}
}
本教程示例也会有所帮助。
问候,
This tutorial sample will help as well.
Regards,
这篇关于代码没有在asp中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文