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

GridDropDownColumn : Concatenate on ListTextField

1 Answer 75 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brian Foster
Top achievements
Rank 1
Brian Foster asked on 20 Oct 2009, 06:40 PM
I currently have a RadGrid control, with a GridDropDownColumn as one of the columns referring to another table in my database structure. See here:
 <telerik:GridDropDownColumn DataField="OptionCategoryID" DataType="System.Int32" HeaderText="Option Category"   
UniqueName="OptionCategoryID" DataSourceID="getOptionCategories" ListTextField="Name" ListValueField="OptionCategoryID">  
</telerik:GridDropDownColumn> 
It's working great, but I wanted to know if there was a way to concatenate the ListTextField using two fields from the datasource? Using the OptionCategoryId and Name to display something similar to the following in the dropdown:

123 - Option1
234 - Option2

Any assistance would be appreciated.
By the way, I'm using OpenAccess as my DAL.

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 21 Oct 2009, 06:03 AM
Hi Brian,

Give a try with following code snippet in order to change the combobox item text explicitly.

C#:
 
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
    { 
        GridEditableItem item = (GridEditableItem)e.Item; 
        RadComboBox combo = (RadComboBox)item["OptionCategoryID"].Controls[0]; 
        combo.ItemDataBound += new RadComboBoxItemEventHandler(combo_ItemDataBound); 
    } 
void combo_ItemDataBound(object sender, RadComboBoxItemEventArgs e) 
    RadComboBoxItem item = (RadComboBoxItem)e.Item; 
    item.Text = item.Value + " - " + item.Text;  // Change the combo item text 

-Shinu.
Tags
Grid
Asked by
Brian Foster
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or