Adding items to RadCombo Dynamic and manually

5 posts, 0 answers
  1. Debashis Pyne
    Debashis Pyne avatar
    66 posts
    Member since:
    Apr 2010

    Posted 30 Aug 2010 Link to this post

    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...

     

     

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 30 Aug 2010 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Debashis Pyne
    Debashis Pyne avatar
    66 posts
    Member since:
    Apr 2010

    Posted 31 Aug 2010 Link to this post

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

    Posted 31 Aug 2010 Link to this post

    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.
  6. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 31 Aug 2010 Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017