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

[Solved] Display more than 1 item

2 Answers 102 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 19 May 2009, 10:46 PM
I have a radcombo box that has the users First Name and Last Name. When the user selects I want both the first and last name to appear in the selected value, Like after you select the name it will say like John Smith. I am only able to get John.

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 20 May 2009, 06:57 AM
Hi Ryan,

Try the following code snippet and see whether it helps.

CS:
 
protected void RadComboBox3_ItemDataBound(object sender, RadComboBoxItemEventArgs e) 
    DataRowView dataSourceRow = (DataRowView)e.Item.DataItem; 
    e.Item.Text = dataSourceRow[0] + " " + dataSourceRow[1]; 

And here is the ASPX,
 
<telerik:RadComboBox Width="200px" DropDownWidth="270px" Height="100px" ID="RadComboBox3" HighlightTemplatedItems="true" DataValueField="LastName" MarkFirstMatch="false" DataSourceID="SqlDataSource1" runat="server" OnItemDataBound="RadComboBox3_ItemDataBound" > 
<HeaderTemplate> 
    <table style="width: 250px;" cellspacing="0" cellpadding="0"
        <tr> 
            <td style="width: 50px;"
                First Name</td> 
            <td style="width: 200px;"
                Last Name</td> 
        </tr> 
    </table> 
</HeaderTemplate> 
<ItemTemplate> 
    <table style="width: 250px;" class="comboTable" cellspacing="0" cellpadding="0"
        <tr> 
            <td style="width: 50px;"
                <div class='comboItem'
                    <%#DataBinder.Eval(Container.DataItem, "FirstName")%> 
                </div> 
            </td> 
            <td style="width: 200px;"
                <div class='comboItem'
                    <%#DataBinder.Eval(Container.DataItem, "LastName")%> 
                </div> 
            </td> 
        </tr> 
    </table> 
</ItemTemplate> 
</telerik:RadComboBox> 

Thanks,
Shinu.
0
Saed
Top achievements
Rank 1
answered on 20 May 2009, 11:12 PM
Well, personally I accomplish that without the need to define both entries as Templates. Simply DataBind combo without specifying DataTextField, then use the ItemDataBound as Shinu suggested.

Hope this helps.

Regards,
Saed
Tags
ComboBox
Asked by
Ryan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Saed
Top achievements
Rank 1
Share this question
or