add "choose item" to combobox

3 posts, 1 answers
  1. Ronen
    Ronen avatar
    29 posts
    Member since:
    Aug 2010

    Posted 08 Aug 2010 Link to this post

    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. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 09 Aug 2010 Link to this post

    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.
  3. Ronen
    Ronen avatar
    29 posts
    Member since:
    Aug 2010

    Posted 10 Aug 2010 Link to this post

    thanks, exactly what i did , i forgot about it.
Back to Top