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

add "choose item" to combobox

2 Answers 47 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Ronen
Top achievements
Rank 1
Ronen asked on 08 Aug 2010, 09:13 AM
Hi, when i used the standard asp.net dropdown control , i was able to bind a datasource to it , and also add one more item at the top of the list manually which says "choose company" , so user must select one company from the list in order to pass the validation.

I don't see i can do that with the combobox.
it always shows the list it got from the datasource and the first company is chosen by default. so no required validation  error can occur.
how can i implement the same as i did with the dropdown control?

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 09 Aug 2010, 07:19 AM
Hello,


You can either perform this from code behind or directly in aspx markup. For adding the new item fom mark-up, set the 'AppendDataBoundItems' property of RadComboBox to "True". Here is an example shown below:

mark-up:
<telerik:RadComboBox ID="RadComboBox1" runat="server" DataSourceID="SqlDataSource1" DataTextField="CustomerID" AppendDataBoundItems="true"
    DataValueField="OrderID" OnDataBound="RadComboBox1_DataBound">
    <Items>
        <telerik:RadComboBoxItem Text="Choose company" />
    </Items>
</telerik:RadComboBox>


Here is the code snippet to perform the same form code behind.

C#:
protected void RadComboBox1_DataBound(object sender, EventArgs e)
{
    RadComboBoxItem item = new RadComboBoxItem("Choose company");
    RadComboBox1.Items.Insert(0, item);
}

[Note: In both cases, you need to set the InitialValue property of RequiredFieldValidator as "Choose company", since the item is teh default one.]


Regards,
Shinu.
0
Ronen
Top achievements
Rank 1
answered on 10 Aug 2010, 12:49 PM
thanks, exactly what i did , i forgot about it.
Tags
ComboBox
Asked by
Ronen
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ronen
Top achievements
Rank 1
Share this question
or