Need help adding an item to a ComboBox

2 posts, 0 answers
  1. toddhd
    toddhd avatar
    21 posts
    Member since:
    Aug 2006

    Posted 18 Jan 2011 Link to this post

    I have a RadComboBox setup to display Checkboxes, like this:

    					<telerik:RadComboBox ID="cmbLocation" Name="Location" runat="server" DataTextField="Key" DataValueField="Value" TabIndex="18" Width="214"
    OnClientDropDownClosing="OnClientDropDownClosing" MarkFirstMatch="true" AllowCustomText="false">
    <asp:CheckBox runat="server" ID="chkLocation" Text='<%# Eval("Key")%>'/> 
    The ComboBox is then simply bound to a List<KeyValuePair<string,int>> datasource in code behind.

    I need to add an item to the top of the list that simply says "ALL". I really don't need a Checkbox in this item, for what it is worth.

    I am currently doing this:
                cmbLocation.Items.Insert(0, new RadComboBoxItem(Common.All, "-1"));
    This works more or less. When I run the app, the ComboBox reads "All". But there is also a blank checkbox in the first position. I don't want that to be there. But I do need to be able to tell if All is selected.

    WHen I look in the generated HTML code, I see that the first item is only an <input> (type of checkbox). All the rest of the items have both a <label> and an <input>.

    What's the right way to add a default item here?
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 19 Jan 2011 Link to this post

    Hello Toddhd,

    You can try adding Header Template to achieve the same functionality. A sample code given below.

    <telerik:RadComboBox ID="RadComboBox1" AppendDataBoundItems="true" runat="server" >
                  <asp:CheckBox runat="server" ID="CheckBox1" OnClick="OnClick();" />
                  <%# DataBinder.Eval(Container, "Text") %>
                  <telerik:RadComboBoxItem Value="10/10/2010" Text="10/10/2010" />
                  <telerik:RadComboBoxItem Value="10/3/2010" Text="10/3/2010" />
                  <telerik:RadComboBoxItem Value="10/10/2010" Text="10/10/2010" />
                  <telerik:RadComboBoxItem Text="Date1" IsSeparator="true" />
              <div style="width:100%;height:100%;" onclick="closeCombo();">All </div>

    function closeCombo()
          var comboBox = $find("<%= RadComboBox1.ClientID %>");

Back to Top