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

combobox load on demand without datasource control

2 Answers 127 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Vlad
Top achievements
Rank 1
Vlad asked on 30 Aug 2011, 02:49 AM
Is there  an example of combobox load on demand
without  using datasource control  but directly from business object at runtime  ?

2 Answers, 1 is accepted

Sort by
0
Vlad
Top achievements
Rank 1
answered on 30 Aug 2011, 06:25 PM
I have found something simular to what I need in demos:
/Controls/Examples/Integration/GridInCombobox/DefaultCS.aspx

but I do not want to use grid,  I just need google like suggestion functionality so people can
use arrow keys to navigate up/down suggested strings in dropdown. The example above behaves unnatural when
arrow keys are used.
I've done this many times using jquery in php but for this project I would like
to stay away from touching javascript  and also do not want to use datasource controls of any type.
0
Accepted
Kalina
Telerik team
answered on 03 Sep 2011, 12:40 PM
Hi Vlad,

You can easily create a list of objects and populate the RadComboBox at ItemsRequested event handler:

<telerik:RadComboBox ID="RadComboBox1" runat="server" 
    ShowDropDownOnTextboxClick="false"
    EnableLoadOnDemand="true"
    OnItemsRequested="RadComboBox1_ItemsRequested">
</telerik:RadComboBox>

protected void RadComboBox1_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
    RadComboBox combo = sender as RadComboBox;
             
    List<TestItems> items = ComboObjectData.GetItems();
    var result = from item in items
                    where item.Name == e.Text
 
                    select new
                    {
                        item.ID,
                        item.Name
                    };
 
    foreach (var i in result)
        combo.Items.Add(new RadComboBoxItem(i.Name, i.ID.ToString()));
 
}

public class ComboObjectData
{
    public ComboObjectData()
    {
        //
        // TODO: Add constructor logic here
        //
    }
 
    public static List<TestItems> GetItems()
    {
        List<TestItems> itemsList = new List<TestItems>();
        itemsList.Add(new TestItems(1, "a"));
        itemsList.Add(new TestItems(2, "b"));
        itemsList.Add(new TestItems(3, "c"));
        itemsList.Add(new TestItems(4, "d"));
        itemsList.Add(new TestItems(5, "e"));
        itemsList.Add(new TestItems(6, "f"));
        return itemsList;
    }  
}
 
public class TestItems
{
    private string _text;
    private int _id;
 
    public string Name
    {
        get { return _text; }
        set { _text = value; }
    }
    public int ID
    {
        get { return _id; }
        set { _id = value; }
    }
 
    public TestItems(int id, string text)
    {
        _id = id;
        _text = text;
    }
}


All the best,
Kalina
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
General Discussions
Asked by
Vlad
Top achievements
Rank 1
Answers by
Vlad
Top achievements
Rank 1
Kalina
Telerik team
Share this question
or