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

Need help adding an item to a ComboBox

1 Answer 55 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
toddhd
Top achievements
Rank 1
toddhd asked on 18 Jan 2011, 10:31 PM
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">
<ItemTemplate>
<asp:CheckBox runat="server" ID="chkLocation" Text='<%# Eval("Key")%>'/> 
</ItemTemplate>                    
</telerik:RadComboBox>
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?

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Jan 2011, 08:38 AM
Hello Toddhd,

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

aspx:
<telerik:RadComboBox ID="RadComboBox1" AppendDataBoundItems="true" runat="server" >
          <ItemTemplate>
              <asp:CheckBox runat="server" ID="CheckBox1" OnClick="OnClick();" />
              <%# DataBinder.Eval(Container, "Text") %>
              text
          </ItemTemplate>
          <Items>
              <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" />
          </Items>
          <HeaderTemplate>
          <div style="width:100%;height:100%;" onclick="closeCombo();">All </div>
          </HeaderTemplate>
</telerik:RadComboBox>

JavaScript:
function closeCombo()
  {
      var comboBox = $find("<%= RadComboBox1.ClientID %>");
      comboBox.hideDropDown();
      comboBox.set_text("All");   
  }


Thanks,
Shinu.
Tags
ComboBox
Asked by
toddhd
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or