Combobox in a DataForm

2 posts, 0 answers
  1. Edward
    Edward avatar
    84 posts
    Member since:
    Feb 2011

    Posted 15 Jul 2015 Link to this post

    Probably a very noob question: 

    Supposed I have a RadComboBox in the ItemTemplate of a RadDataForm.

    The entity "Client" have a column called "genderID", which should be bound to the dataform.

    Another entity "DefGender" should be bound to the combobox, with "genderID" as the DataValueField, "genderText" as the DataTextField, and I want to somehow bind the SelectedValue to Client.genderID

    How would you do this pragmatically?  It was pretty straight forward in Silverlight, but I couldn't figure this out in ASP.


  2. Eyup
    Eyup avatar
    3296 posts

    Posted 20 Jul 2015 Link to this post

    Hi Edward,

    You can use the following approach to achieve this requirement:
    <telerik:RadComboBox ID="RadComboBox1" runat="server" OnDataBinding="RadComboBox1_DataBinding"></telerik:RadComboBox>
    protected void RadComboBox1_DataBinding(object sender, EventArgs e)
        RadComboBox combo = (RadComboBox)sender;
        RadDataFormDataItem item = (RadDataFormDataItem)combo.NamingContainer;
        // acceess unique item ID
        string customerID = item.GetDataKeyValue("CustomerID").ToString();
        // apply combo settings
        combo.DataTextField = "TextField";
        combo.DataValueField = "ValueField";
        // obtain and set the data source depending on the unique ID
        var dummySource = Enumerable.Range(1, 6).Select(
            x => new { ValueField = x, TextField = "C: " + customerID + ", Book: " + x });
        combo.DataSource = dummySource;
        // select item if present
        combo.DataBound += (s, a) =>
            RadComboBoxItem comboItem = combo.FindItemByValue("3");
            if (comboItem != null)
                comboItem.Selected = true;

    Hope this helps. Please give it a try and let me know about the result.

Back to Top