Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • MuthuKumar 1 post 71 karma points
    Oct 06, 2016 @ 11:30
    MuthuKumar
    0

    AutoCompleteExtender displays html page

    I'm using Visual Web Developer 2010, this is running on Localhost My autcomplete extender is displaying html page source instead of the database results. I was not able to find the solution pls see my code and help me some one.

     function SetContextKey() {
                $find('AutoCompleteExtender1').set_contextKey($get("<%=ddlstate.ClientID %>").value);
            }
    
    <asp:DropDownList CssClass="select" ID="ddlstate" runat="server">       
                    <asp:ListItem Value="Select">Select</asp:ListItem>   
                    <asp:ListItem Value="Andhra Pradesh">Andhra Pradesh</asp:ListItem>                                
                    <asp:listitem   Value="Andamans">Andamans</asp:listitem>     
                    <asp:listitem   Value="Assam">Assam</asp:listitem>
                    <asp:listitem   Value="Bihar">Bihar</asp:listitem>
                    <asp:listitem   Value="Chhatisgarh">Chhatisgarh</asp:listitem>
                    <asp:listitem  value="Delhi">Delhi </asp:listitem>
                    <asp:listitem Value="Gujarat">Gujarat</asp:listitem>
                    <asp:listitem  value="Haryana">Haryana</asp:listitem>
                    <asp:listitem  value ="Himachal Pradesh">Himachal Pradesh</asp:listitem>                
                    <asp:listitem  Value="Jammu & Kashmir"> Jammu & Kashmir</asp:listitem>
                    <asp:listitem   Value="Jharkhand">Jharkhand</asp:listitem>
                    <asp:listitem  Value="Karnataka">Karnataka</asp:listitem>
                    <asp:listitem   Value="Kerala">Kerala</asp:listitem>
                    <asp:listitem  Value="Maharashtra">Maharashtra</asp:listitem>
                    <asp:listitem   Value="Rajasthan">Rajasthan</asp:listitem>
                    <asp:listitem   Value="Sikkim">Sikkim</asp:listitem>
                    <asp:listitem   Value="Tamil Nadu">Tamil Nadu</asp:listitem>
                    <asp:listitem  value ="Telangana">Telangana</asp:listitem>
                    <asp:listitem   Value="Uttar Pradesh">Uttar Pradesh</asp:listitem>
                    <asp:listitem   Value="Uttaranchal">Uttaranchal</asp:listitem>
                    <asp:listitem   Value="West Bengal">West Bengal</asp:listitem>                    
                    </asp:DropDownList>
                    <asp:RequiredFieldValidator CssClass="validation" ForeColor="#c4e427"
                    ID="RequiredFieldValidator5" runat="server"  
                    ErrorMessage="Please select your state." ControlToValidate="ddlstate" InitialValue="Select"></asp:RequiredFieldValidator>
                    <div class="clr"></div>
                    <label class="lable">City</label>
                     <asp:Textbox ID="txtCity" runat="server"  class="inputbox" onkeypress="return noNumeric(event)" onblur="SetContextKey()" ></asp:Textbox>
                    <cc1:AutoCompleteExtender ScriptPath="webservice.asmx" ServiceMethod="SearchCustomers"
                    MinimumPrefixLength="1"
                    CompletionInterval="100" EnableCaching ="false"   CompletionSetCount="10" 
                    TargetControlID="txtCity" UseContextKey = "true" FirstRowSelected ="false" 
                    ID="AutoCompleteExtender1" runat="server" CompletionListCssClass="AutoExtender"
                    CompletionListItemCssClass="AutoExtenderList"
                    CompletionListHighlightedItemCssClass="AutoExtenderHighlight"
                    CompletionListElementID="divwidth" >
                    </cc1:AutoCompleteExtender>
                    This is my service code:
    public List<string> SearchCustomers(string prefixText, int count, string contextKey)
        {
            try
            { 
                SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["TeN"].ConnectionString);
                using (SqlCommand cmd = new SqlCommand())
                {
                    string cmdText = "select cityname from NewCity where " +
                         "StateName like '" + contextKey + "%'";
                    //cmd.Parameters.AddWithValue("@SearchText", prefixText);
                    if (contextKey != "0")
                    {
                        cmdText += " and CityName like  '" + prefixText + "%'";
                        //  cmd.Parameters.AddWithValue("@City", contextKey);
                    }
                    cmd.CommandText = cmdText;
                    cmd.Connection = conn;
                    conn.Open();
                    List<string> customers = new List<string>();
                    using (SqlDataReader sdr = cmd.ExecuteReader())
                    {
                        while (sdr.Read())
                        {
                            customers.Add(sdr["cityname"].ToString());
                        }
                    }
                    conn.Close();
                    if (customers.Count > 0)
                    {
                        return customers;
                    }
                    else
                    {
                        customers.Add("data not found");
                        return customers;
    
                    }
    
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies