1

I am using Telerik controls on my aspx page. I have cascading radcombo boxes(dropdown box). I have 3 of them on my page. the values of 2nd rad combo box depends on the 1st and the 3rd depends on selection of 2nd. The thing is that i want to include a select all option in the 3rd dropdown. The values are coming from a database i.e all of them are data bound. How can i add a 'select all' option in the combo boxes? i tried it using parameters.insert function in c#, but does not work. i tried adding in the control itself but not showing up with that either.

Can someone please help?

gsb
  • 5,520
  • 8
  • 49
  • 76

3 Answers3

2

Simple create a new RadComboBoxItem and add it to the RadComboBox. See example below.

RadComboBoxItem myItem = new RadComboBoxItem();
myItem.Text = "Select All";
myItem.Value = "SelectAll";

//Add it as the last item
myComboBox.Items.Add(myItem);

//OR

/Add it as the first item
myComboBox.Insert(0, myItem);

EDIT

Make sure you're adding the item after the control has been bound by putting our code in the DataBound event of the control:

protected void RadComboBox1_DataBound(object sender, EventArgs e) 
{ 
    var combo = (RadComboBox)sender; 
    combo.Items.Insert(0, new RadComboBoxItem("Select All", "SelectAll")); 
}

Here's some documentation from Telerik that explains how to do this properly: http://www.telerik.com/help/aspnet-ajax/combobox-insert-default-item-when-databinding.html.

NOTE: If the above method does not work, make sure you have set myComboBox.AppendDataBoundItems = true.

Rashad
  • 11,057
  • 4
  • 45
  • 73
James Hill
  • 60,353
  • 20
  • 145
  • 161
  • Hi James, I have tried this. but this dosent work. the page loads fine, but i cannot see the "select all" option. – gsb Jul 01 '11 at 18:05
  • You're probably doing it BEFORE the databinding. See above edits. – James Hill Jul 01 '11 at 18:06
  • James, I can see the select all option now. :) but the problem is that the items are shown twice in the dropdown inspite of a distinct keyword. Any suggestions? – gsb Jul 01 '11 at 18:30
  • @user819911, I suggest opening a new question with a SQL or LINQ specific question. Trying to help in comments is always messy – James Hill Jul 01 '11 at 18:37
0

Since the OP doesn't indicate a preference for a code behind solution we should mention the declarative approach which is also totally valid and avoids the need for the DataBound event handler:

<telerik:RadComboBox ID="RadComboBox1" runat="server" DataSourceID="SomeDataSource" AppendDataBoundItems="true" ... >
    <Items>
        <telerik:RadComboBoxItem Text="Select All" Value="Select All" />
    </Items>
</telerik:RadComboBox>

James' reference to Telerik still applies plus this one: RadComboBox Items - Declaring the Items In-line

JohnC
  • 1,797
  • 1
  • 18
  • 26
-1
Protected Sub CreateSelectAllUsersCheckBox()
        Dim chkSelectAllUsers As New CheckBox
        chkSelectAllUsers.Text = "Select All Users"
        chkSelectAllUsers.ID = "chk1"
        Dim radComboBoxItem As New RadComboBoxItem
        radComboBoxItem.Text = "Select All Users"  
    radComboBoxItem.Controls.Add(chkSelectAllUsers)    
        cmbRoleName.Items.Insert(0, radComboBoxItem)

        radComboBoxItem.DataBind()
    End Sub
Prudhvi
  • 2,276
  • 7
  • 34
  • 54
Seema
  • 1