Saturday 17 August 2013

suggestion in textbox in asp.net

 <td>
    <asp:TextBox ID="TextBox1" runat="server" ForeColor="Black" AutoPostBack="True"></asp:TextBox>
    <asp:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server"
        CompletionInterval="10" DelimiterCharacters="" Enabled="True"
        MinimumPrefixLength="1" ServicePath="" TargetControlID="TextBox1"
        UseContextKey="True" ServiceMethod="GetCompletionList">
    </asp:AutoCompleteExtender>
    </td>


 [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
       
        public static string[] GetCompletionList(string prefixText, int count, string contextKey)
        {
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con1"].ToString());
            con.Open();
            SqlCommand cmd = new SqlCommand("select * from Patient_master Where Patient_Code LIKE '" + prefixText + "%' order by Patient_Code", con);
            SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            List<string> li = new List<string>();
            while (dr.Read())
            {
                li.Add(dr["Patient_Code"].ToString());
            }
            return li.ToArray();
        }

No comments:

Post a Comment