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

Preselecting items.

3 Answers 19 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
JC
Top achievements
Rank 1
JC asked on 30 Jul 2013, 01:03 PM
Hi

Is it possible to preselect item in a radautocompletebox at the time of loading? If possible please help me with some examples?

Thanks
JC

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 30 Jul 2013, 01:06 PM
Hi JC,

As far as I know RadAutoCompleteBox does not support preselecting items, coming from its data source, out-of-the-box. But, you still can manipulate the data source itself so you will be able to have preselected entries. Please have a look at the following code which uses an ASP SQLDataSource.

ASPX:
<telerik:RadAutoCompleteBox ID="RadAutoCompleteBox2" runat="server" Width="200px"
    DropDownWidth="200px" DataSourceID="SqlDataSource1" DataTextField="Name" DataValueField="ID"
    OnDataBound="RadAutoCompleteBox2_DataBound">
</telerik:RadAutoCompleteBox>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>"
    SelectCommand="SELECT [ID], [CountryID], [Name] FROM [Cities]" OnSelecting="SqlDataSource1_Selecting">
</asp:SqlDataSource>

C#:
protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        DataSourceSelectArguments args = new DataSourceSelectArguments();
        DataView view = (DataView)SqlDataSource1.Select(args);
        DataTable table = view.ToTable();
  
        string ID = "", countryID = "", name = "";
        for (int i = 0; i < table.Rows.Count; i++)
        {
            ID = table.Rows[i].ItemArray[0].ToString();
            countryID = table.Rows[i].ItemArray[1].ToString();
            name = table.Rows[i].ItemArray[2].ToString();
  
            if (!string.IsNullOrEmpty(ID) && ID == "1")
            {
                if (!string.IsNullOrEmpty(name))
                {
                    RadAutoCompleteBox2.Entries.Add(new AutoCompleteBoxEntry(name, ID));
                }
            }
        }
    }
}

Thanks,
Shinu.
0
Kamelia
Top achievements
Rank 1
answered on 12 Nov 2014, 06:49 AM
Hi, Is it possible to preselect items in a radautocompletebox in windows form ???

I have some items which I want to have them in my radautocompletebox , so I can remove or add items in it . AND I need it to show me the items I had entered before.
thank you in advance

0
Nencho
Telerik team
answered on 14 Nov 2014, 02:46 PM
Hello,

In order to predefine some entries for the RadAutoCompleteBox, you need to use the Entries collection of the control. Please consider the following approach:

RadAutoCompleteBox1.Entries.Add(new AutoCompleteBoxEntry("Text", "Value"));

Regards,
Nencho
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
AutoCompleteBox
Asked by
JC
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Kamelia
Top achievements
Rank 1
Nencho
Telerik team
Share this question
or