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

ComboBox text from multiple fields

1 Answer 186 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Farhan
Top achievements
Rank 1
Farhan asked on 06 Sep 2011, 06:58 PM
Hi,

   I have a combo box in the edit Form in a radgrid. Im using Entity Framework and a business layer class to return an IEnumerable List
<Employees> to bind to the grid. When the edit form comes up I want the titles and names of the employees to be shown in the combo box. like as the  DataTextField like :

"{Title}:" + {FirstName}  + " " + {LastName}

and I want to bind another property in the Employee class employee_Id as the DataValueField.

Can someone show me how to do this, I am doing something similar in a GridCalculatedColumn where I am able to combine these multiple fields and show them in an expression like shown above. Please see Grid calculated column below. How can I bind the combo box like this so i can see the title: FirstName  Lastname  in the text field. Please note that I dont want a multi column grid as shown in this example here
http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/multicolumncombo/defaultcs.aspx  

I want to show them all together. and be able to bind the employee_id property as the DataValueField so when i submit the form I can read that, can someone please show me how to do this in code, thanks.   Please see below for the CalculatedGridColumn where i am showing same information.

<telerik:GridCalculatedColumn SortExpression="Employee.FirstName" HeaderText="Employees" AutoPostBackOnFilter="true"
 DataFields="Employee.Title,Employee.FirstName, Employee.LastName" Expression='{0}  + ":" + {1} + " " + {2}' >                        
 <HeaderStyle HorizontalAlign="Left" Width="30%" />
                         <ItemStyle HorizontalAlign="Left" />
                    </telerik:GridCalculatedColumn>

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 07 Sep 2011, 07:55 AM
Hello,

Which Method are you used for binding the Radcombobox.
For ex : SQldataSource,Linq,DataTable assign to DataSource in Radcombobox.

Note :to achieve this thing without multicolumn you have to create one more property or column in your source.
or
 <telerik:RadComboBox ID="RadComboBox1" runat="server">
            <ItemTemplate>
            <%# Eval("ID") + " : " + Eval("Name")%>
            </ItemTemplate>
        </telerik:RadComboBox>

.................
 dynamic data = new[] { new { ID = 1 ,Name="Name1",Address="Address1"},
            new { ID = 1,Name="Name2",Address="Address2" },
            new { ID = 0,Name="Name3",Address="Address3" },
            new { ID = 1 ,Name="Name4",Address="Address4"}
        };

        RadComboBox1.DataValueField = "ID";
        RadComboBox1.DataTextField = "Name";
        RadComboBox1.DataSource = data;
        RadComboBox1.DataBind();
.............
................



Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Farhan
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or