Tuesday 22 July 2014

Ajax AutoCompletEextender example.



CSS:


 <style type="text/css"> 

        .completionList {
        border:solid 1px Gray;
        margin:0px;
        padding:3px;
        height: 120px;
        overflow:auto;
        background-color: #FFFFFF;     
        } 
        .listItem {
        color: #191919;
        } 
        .itemHighlighted {
        background-color: #ADD6FF;       
        }
        .style97
        {
            height: 24px;
            width: 337px;
        }
        .style98
        {
            height: 40px;
            width: 337px;
        }
        .style103
        {
            width: 137px;
            height: 33px;
        }
        .style104
        {
            height: 33px;
        }
    

    </style>

HTML MARKUP:


 <td class="style97" >

        <asp:TextBox ID="txtsempidid" runat="server" AutoCompleteType="Disabled"  CssClass="form_txt"              Enabled="False" MaxLength="12"   ontextchanged="txtsempid_TextChanged" 
          Style="position: static" Width="142px">
     </asp:TextBox>

 </td>

SERVER SIDE METHODS:


 [System.Web.Script.Services.ScriptMethod()]

    [System.Web.Services.WebMethod]
    public static List<string> SearchCustomers(string prefixText)
    {
        using (NpgsqlConnection con = new NpgsqlConnection())
        {
            con.ConnectionString = ConfigurationManager.ConnectionStrings["Database Connection String1"].ConnectionString;
            using (NpgsqlCommand cmd = new NpgsqlCommand())
            {

                string cmdText = @"select Empid from common.emp_mast where  Empid like @SearchText || '%' ";

                cmd.Parameters.Add("@SearchText", prefixText);
               

                cmd.CommandText = cmdText;

                cmd.Connection = con;
                con.Open();
                List<string> empid= new List<string>();

                using (NpgsqlDataReader sdr = cmd.ExecuteReader())

                {
                    while (sdr.Read())
                    {
                        empid= .Add(Convert.ToString(sdr["Empid "]));
                    }
                }
                con.Close();
                return  empid;
            }
        }

    }

No comments:

Post a Comment