Items not display in AutocompleteBox from serverside databinding

2 posts, 0 answers
  1. Rahul
    Rahul avatar
    39 posts
    Member since:
    Jan 2014

    Posted 29 Jan 2014 Link to this post

    Hi,
          In my case I have one  AutoCompleteBox. Its Databinding  From Server Side i.e.code behind. but Data not showing in AutoCompleteBox so provide solution.
    My code is..
    Client Side:
    <telerik:RadAutoCompleteBox ID="cmplt_agent" Runat="server" InputType="Token" 
                                                                        Width="80%"  Filter="StartsWith"
                                                                        DropDownWidth="200" DropDownHeight="150" AllowCustomEntry="true"
                                                                        ontextchanged="cmplt_agent_TextChanged" >       
                                                                     <TokensSettings AllowTokenEditing="true" /> 
                                                                    </telerik:RadAutoCompleteBox>

    code behind:
      public void GetAgent()
            {
                AgentIdTitle = cs.GetAgentIdTitle(Ld.SubscriberInformationId);
                cmplt_agent.DataSource = AgentIdTitle;
                cmplt_agent.DataTextField = "Title";
                cmplt_agent.DataValueField = "Id";
                cmplt_agent.DataBind();
            }

    Thanks,
    Rahul
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 29 Jan 2014 in reply to Rahul Link to this post

    Hi Rahul,

    Please have a look into the sample code snippet which works fine at my end.

    ASPX:
    <telerik:RadAutoCompleteBox ID="RadAutoCompleteBox1" runat="server" DropDownHeight="150"
        Width="80%" InputType="Token" DropDownWidth="200" Filter="StartsWith" AllowCustomEntry="true">
        <TokensSettings AllowTokenEditing="true" />
    </telerik:RadAutoCompleteBox>

    C#:
    protected void Page_Load(object sender, EventArgs e)
    {
        GetAgent();
    }
    public void GetAgent()
    {
        String connstring = WebConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
        SqlConnection conn = new SqlConnection(connstring);
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = new SqlCommand("SELECT * from City ", conn);
        DataTable data = new DataTable();
        conn.Open();
        try
        {
            adapter.Fill(data);
            RadAutoCompleteBox1.DataSource = data;
            RadAutoCompleteBox1.DataTextField = "Cityname";
            RadAutoCompleteBox1.DataValueField = "Countryname";
            RadAutoCompleteBox1.DataBind();
        }
        finally
        {
            conn.Close();
        }
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top