This is a migrated thread and some comments may be shown as answers.

Items not display in AutocompleteBox from serverside databinding

1 Answer 119 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Rahul
Top achievements
Rank 1
Rahul asked on 29 Jan 2014, 12:42 PM
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

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 30 Jan 2014, 05:02 AM
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.
Tags
AutoCompleteBox
Asked by
Rahul
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or