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,