Combobox with template

6 posts, 0 answers
  1. Blop
    Blop avatar
    19 posts
    Member since:
    Feb 2012

    Posted 25 Apr 2012 Link to this post

    Hello. I've a little issue to get the combobox as I want it to be.
    I have, in a database, a table "colors" (let say it only has an "ID" and "code" fields). I want to populate a radcombobox with a small square of each color.

    Here's what I do:

    <telerik:RadComboBox ID="rcbProdColors" Width="60" runat="server" MarkFirstMatch="false"  AllowCustomText="false" DataValueField="ID" >
                  <ItemTemplate>
                         <div style=" height:15px;width:15px;border:solid black 1px;background-color: #<%# Eval("Code")%>"></div>                                
                </ItemTemplate>                      
    </telerik:RadComboBox>

    And in the code behind:

    Dim query = (From c In db.Colors Select c)
    rcbProdColors.DataSource = query
    rcbProdColors.DataBind()

    It's working but not completly.
    I have two main issues:

    First: The first "item" of the combobox isnt a color square but text saying "colors". I dont know where it comes from, my guess is it is the name of the table in the database. How can I remove it and have a color square as first item?

    Second: More important: I can't select anything... whatever my choice, the selected item will always be the first item (in this case the text "colors"). How can I make a selection on this combobox?

    Thanx in advance for yours answers.
  2. Blop
    Blop avatar
    19 posts
    Member since:
    Feb 2012

    Posted 26 Apr 2012 Link to this post

    No one to help me out?
  3. Cat Cheshire
    Cat Cheshire avatar
    128 posts
    Member since:
    Jun 2010
  4. Blop
    Blop avatar
    19 posts
    Member since:
    Feb 2012

    Posted 26 Apr 2012 Link to this post

    Well thanks but it's almost the same things I do... I don't understand why can't I select an Item and why there's a first item created wich has nothing to do there...
  5. Blop
    Blop avatar
    19 posts
    Member since:
    Feb 2012

    Posted 27 Apr 2012 Link to this post

    Anyone hanging out here?
  6. Ivana
    Admin
    Ivana avatar
    657 posts

    Posted 01 May 2012 Link to this post

    Hi,

    Try to specify the DataTextField and DataValueField when databinding the RadComboBox:
    http://www.telerik.com/help/aspnet-ajax/combobox-data-binding-datatable-set-view.html.

    All the best,
    Ivana
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top