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

[Solved] Concatenate displayed text in GridDropDownColumn from multiple database columns

2 Answers 257 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Soren Michelsen
Top achievements
Rank 1
Soren Michelsen asked on 11 Nov 2009, 07:36 PM
Hi,

In my database, I have three fields that I need displayed in one GridDropDownColumn:
Value: zipcode
Text: City (State Zip)

For example:
value: 98027
text: "Issaquah (WA 98027)"

So, basically, instead of setting the ListTextField property to "City", i need it to be a combination of City, State and Zip.

Any ideas, anyone?
Jeppe Jespersen
Denmark

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 12 Nov 2009, 06:41 AM
Hello Jeppe,

Check out the following code to achieve the scenario:
aspx:
<telerik:GridDropDownColumn UniqueName="DropDownColumn" DataSourceID="SqlDataSource1" 
 ListTextField="City" ListValueField="zipcode" DataField="City">                         
</telerik:GridDropDownColumn> 

c#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
        { 
            GridEditableItem editItem = (GridEditableItem)e.Item; 
            RadComboBox combo = (RadComboBox)editItem["DropDownColumn"].Controls[0]; 
            combo.ItemDataBound += new RadComboBoxItemEventHandler(combo_ItemDataBound); 
        } 
    } 
 
    void combo_ItemDataBound(object sender, RadComboBoxItemEventArgs e) 
    { 
        RadComboBoxItem item = (RadComboBoxItem)e.Item; 
        DataRowView dr = (DataRowView)e.Item.DataItem; 
        item.Text = item.Text + " ( " + dr["State"].ToString() + " " + dr["Zip"].ToString() + " ) "
        
    } 

Thanks
Princy.
0
Soren Michelsen
Top achievements
Rank 1
answered on 12 Nov 2009, 08:31 AM
Great, Thank you so much!

-jeppe

Tags
Grid
Asked by
Soren Michelsen
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Soren Michelsen
Top achievements
Rank 1
Share this question
or