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

DataTextField+itemtemplate+selected text

2 Answers 119 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
-DJ-
Top achievements
Rank 1
-DJ- asked on 23 Oct 2009, 09:58 AM
Hi guys,

1)
When using an Itemtemplate, shouldn't the selected item keep the text it has in the list?
            <ItemTemplate> 
                <div class="rcbItem"
                    <%#Eval("RefereeFirstName") & " " & Eval("RefereeMidName") & " " & Eval("RefereeLastName")%> 
               </div> 
            </ItemTemplate> 

Now, in the combobox list you get the full names of the referees, while the selected item only displays the first name.

When binding the data I have stated:
combo.DataTextField = "RefereeFirstName"
so in a way this might be normal, but I would think the itemtemplate should override it for the selected item as well as the others.

Not setting the DataTextField only results in the classic system.data.datarowview text being displayed instead.
So, in order to get all the names for the selected item, what would you do?

2)
Another problem I'm getting related to using an itemtemplate is when adding an item dynamically:

combo.Items.Insert(0, New RadComboBoxItem("My Text", 0)) works fine in itself, the item is inserted. But it has no text in the list, while the text is displayed when the item is selected.

I am using Q1 2009.

Regards,
-DJ-


2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 23 Oct 2009, 11:09 AM
Hello,

One suggestion is changing the RadComboBoxItem text dynamically in ItemDataBound event instead of adding ItemTemplate. Here is the code that I tried to achieve this.

C#:
 
protected void RadComboBox2_ItemDataBound(object sender, Telerik.Web.UI.RadComboBoxItemEventArgs e) 
    RadComboBoxItem item = (RadComboBoxItem)e.Item; 
    System.Data.DataRowView dr = (System.Data.DataRowView)e.Item.DataItem; 
    item.Text = item.Text + "  " + dr["FerereeMiddleName"].ToString() + "  " + dr["FerereeLastName"].ToString(); 

And I tried adding combo item and it worked fine in my end. Give a try with following code and see whether it is working fine.
         RadComboBox2.Items.Insert(0, new RadComboBoxItem("My Text", "0"));

Feel free to share the comments,
Shinu.
0
-DJ-
Top achievements
Rank 1
answered on 23 Oct 2009, 03:03 PM
Hey Shinu.

Using the itemdatabound event works perfectly. Once I did, I realized I didn't need the itemtemplate, since I am adding the middle and last name anyway in the itemdatabound event.

As soon as I removed the itemtemplate, the text for the inserted item was displayed as well.

Thanks for your help,
-DJ-

/* Edit */
I've tried marking your post as an answer but it doesn't work.
Tags
ComboBox
Asked by
-DJ-
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
-DJ-
Top achievements
Rank 1
Share this question
or