Click here to Skip to main content
15,917,652 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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;

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
Posted
Updated 30-May-13 19:36pm
v3
Comments
Mayur Panchal 31-May-13 1:55am    
Is it window form application or web application ?
prashant kr 31-May-13 2:09am    
this is code from window application and i have to use this code in web application

1 solution

Hello Prashant,

You won't be able to use your code as is. Instead use AutoCompleteExtender. Sample given below

ASPX Markup
HTML
<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
C#
[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,
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900