Quantcast
Channel: Telerik Forums RSS
Viewing all articles
Browse latest Browse all 94857

Combobox in a DataForm

$
0
0
Hi Edward,

You can use the following approach to achieve this requirement:
<telerik:RadComboBox ID="RadComboBox1" runat="server" OnDataBinding="RadComboBox1_DataBinding"></telerik:RadComboBox>
C#:
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.

Regards,
Eyup
Telerik

Viewing all articles
Browse latest Browse all 94857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>