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

Adding items to RadCombo Dynamic and manually

4 Answers 1015 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Debashis Pyne
Top achievements
Rank 1
Debashis Pyne asked on 30 Aug 2010, 02:44 PM
Hi,

I have a dropdown which binds with a datatable on Page load method.
I want to add a "Select" option to the dropdown on top of the dropdown list.

The following the code that I have used - the issue is the select option is coming at the bottom of the list.

 

 

private void fillddlHeadline()
        {
            DataTable dt = oHead.GetDataActivateHeadlineObserved();
            DrpHeadlineObType.DataSource = dt;
            DrpHeadlineObType.DataTextField = "Module_Content_Text";
            DrpHeadlineObType.DataValueField = "headline_Id";
            DrpHeadlineObType.DataBind();
            RadComboBoxItem item1 = new RadComboBoxItem();
            item1.Text = "Select";
            item1.Value = "0";
            DrpHeadlineObType.Items.Add(item1);
        }

Any ideas?

Thanks...

 

 

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 30 Aug 2010, 02:57 PM
Hi,

Try the following code to add the default item as first item.

C#:
protected void RadComboBox1_DataBound(object  sender, EventArgs e) 
   var combo = (RadComboBox)sender; 
   combo.Items.Insert(0, new RadComboBoxItem("Select", string.Empty)); 
}

Insert a default item when databinding RadComboBox


-Shinu.
0
Debashis Pyne
Top achievements
Rank 1
answered on 31 Aug 2010, 08:10 AM
Hi,

Thanks for this.
However the data still does not bind with the combo box.

For more clarafication, please note that I am binding the combo box with a datatable which has data from the database. I just want to add a "Select" option as the first item in the drop down.

The following the code:

 private void fillddlHeadline()
        {
            MiddleWare.BL.HeadLineObservedType oHead = new MiddleWare.BL.HeadLineObservedType();
            oHead._Module_Id = 1;
            oHead._Language_Id = System.Convert.ToInt32(Session[Session.__Session_Lanuage_Id]);
            oHead._Company_id = System.Convert.ToInt32(Session[Session.__Session_Company_Id]);
            DataTable dt = oHead.GetDataActivateHeadlineObserved();
            DrpHeadlineObType.DataSource = dt;
            DrpHeadlineObType.DataTextField = "Module_Content_Text";
            DrpHeadlineObType.DataValueField = "headline_Id";
            DrpHeadlineObType.DataBind();
        }

The above perfectly binds data to the drop down.
I just need to add a "Select" option to it.

Thanks!
0
Shinu
Top achievements
Rank 2
answered on 31 Aug 2010, 09:14 AM
Hello,


I am not sure about the issue since the code worked fine in my end. Have you set the AppendDataBoundItems property to True as described in the documentation?


-Shinu.
0
Simon
Telerik team
answered on 31 Aug 2010, 12:51 PM
Hello Debashis,

Please also make sure that you have hooked the ItemDataBound event (as suggested by Shinu previously) properly to the RadComboBox. 

Greetings,
Simon
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
ComboBox
Asked by
Debashis Pyne
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Debashis Pyne
Top achievements
Rank 1
Simon
Telerik team
Share this question
or