DataTextField+itemtemplate+selected text

3 posts, 0 answers
  1. -DJ-
    -DJ- avatar
    263 posts
    Member since:
    Oct 2004

    Posted 23 Oct 2009 Link to this post

    Hi guys,

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

    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 text being displayed instead.
    So, in order to get all the names for the selected item, what would you do?

    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.


  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 23 Oct 2009 Link to this post


    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.

    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,
  3. DevCraft R3 2016 release webinar banner
  4. -DJ-
    -DJ- avatar
    263 posts
    Member since:
    Oct 2004

    Posted 23 Oct 2009 Link to this post

    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,

    /* Edit */
    I've tried marking your post as an answer but it doesn't work.
Back to Top