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

How to set the default in a combo box

2 Answers 80 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Bindu
Top achievements
Rank 1
Bindu asked on 01 Aug 2008, 05:43 PM
Hi All,

I have populated the combobox with the data and from that data the mostly likely used item is 'Buy'. so I want to show this on top in the combo box.

How can I do it .

Thanks for all your help.

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Aug 2008, 07:49 AM
Hello Bindu,

Check out the following code snippet to achieve the desired result.
cs:
 protected void RadComboBox1_ItemDataBound(object sender, RadComboBoxItemEventArgs e) 
    { 
        if (e.Item is RadComboBoxItem) 
        { 
            RadComboBoxItem comboitem=(RadComboBoxItem)e.Item; 
            string strtxt = comboitem.Text; 
            if (strtxt == "Buy") 
            { 
                RadComboBox1.Items.Remove(comboitem); 
                RadComboBox1.Items[0].Text = "Buy"
            } 
        } 
    } 

Thanks
Princy.
0
Yana
Telerik team
answered on 04 Aug 2008, 12:23 PM
Hi Princy,

I suggest you subscribe to the DataBound event of RadComboBox and add the following code to your page:

protected void RadComboBox1_DataBound(object sender, EventArgs e)  
{  
   RadComboBoxItem item = RadComboBox1.Items.FindItemByText("Buy");  
   RadComboBox1.Items.Remove(item);  
   RadComboBox1.Items.Insert(0, item);  

Hope this helps.

Best wishes,
Yana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
ComboBox
Asked by
Bindu
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Yana
Telerik team
Share this question
or