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

dynamically add multiple header templates

5 Answers 93 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Tao
Top achievements
Rank 1
Tao asked on 22 May 2013, 09:19 PM
Hi,

Is there a way to add multiple header templates to radcombo with checkbox dynamically?

For example:

Title:Dog
  dog1
  dog2
Title:Cat
  cat1 
  cat2
  cat3
Title:Bird
   Bird1

Right now, I only can add one title template and list all the items together. It would be nice to have a title for each category.
Thanks,

Tao

5 Answers, 1 is accepted

Sort by
0
Tao
Top achievements
Rank 1
answered on 22 May 2013, 11:56 PM
Ok, I find a way to do it. I can add separator between each category. But I'm having another problem now. I'm displaying all the items as checkbox items. And as I do so, the separator will have a checkbox with it too. Any idea how to remove it from separator and only show checkbox for regular items?

Thanks!

0
Plamen
Telerik team
answered on 27 May 2013, 02:19 PM
Hi Tao,

 
Would you please share the code that you used in your implementation so far so we could be more helpful with your actual issue?

Regards,
Plamen
Telerik
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.
0
Tao
Top achievements
Rank 1
answered on 29 May 2013, 12:03 AM
Hi Plamen,

Here is the code. If I don't add label control to radComboxItem, a check box will display in front of the separator.
Dictionary<string, List<string>> dicAnimal = new Dictionary<string, List<string>>();
       List<string> list1 = new List<string>();
       list1.Add("Dog1");
       list1.Add("Dog2");
       list1.Add("Dog3");
 
       dic.Add("Dog", list1);
 
       List<string> list2 = new List<string>();
       list2.Add("Cat1");
       list2.Add("Cat2");
       dic.Add("Cat", list2);
 
       List<string> list3 = new List<string>();
       list3.Add("Bird1");
       list3.Add("Bird2");
       list3.Add("Bird3");
       list3.Add("Bird4");
       dic.Add("Bird", list3);
 
       RadComboBoxItem rcItem = new RadComboBoxItem();
 
       foreach (string animal in dicAnimal.Keys)
       {
           rcItem = new RadComboBoxItem();
           rcItem.IsSeparator = true;
            
           //Label lbl = new Label();
           //lbl.Text = animal;
           //rcItem.Controls.Add(lbl);
 
           rcItem.Text = animal
           radComAnimal.Items.Add(rcItem);
 
           foreach (string name in dicAnimal[animal])
           {
               rcItem = new RadComboBoxItem();
               rcItem.Text = name;
               radComAnimal.Items.Add(rcItem);
           }
       }
 
0
Plamen
Telerik team
answered on 03 Jun 2013, 07:35 AM
Hi Tao,

 
Here is the code that helped me achieve similar functionality:

protected void Page_Load(object sender, EventArgs e)
  {
      Dictionary<string, List<string>> dicAnimal = new Dictionary<string, List<string>>();
     List<string> list1 = new List<string>();
     list1.Add("Dog1");
     list1.Add("Dog2");
     list1.Add("Dog3");
 
     dicAnimal.Add("Dog", list1);
 
     List<string> list2 = new List<string>();
     list2.Add("Cat1");
     list2.Add("Cat2");
     dicAnimal.Add("Cat", list2);
 
     List<string> list3 = new List<string>();
     list3.Add("Bird1");
     list3.Add("Bird2");
     list3.Add("Bird3");
     list3.Add("Bird4");
     dicAnimal.Add("Bird", list3);
 
     RadComboBoxItem rcItem = new RadComboBoxItem();
 
     foreach (string animal in dicAnimal.Keys)
     {
         rcItem = new RadComboBoxItem();
         rcItem.IsSeparator = true;
 
         rcItem.Text = animal;
         RadComboBox1.Items.Add(rcItem);
 
         for (int i = 0; i < dicAnimal[animal].Count; i++)
          {
            rcItem = new RadComboBoxItem();
            rcItem.Text = dicAnimal[animal][i];
             RadComboBox1.Items.Add(rcItem);
 
             Label lbl = new Label();
             lbl.Text = animal+(i+1);
             rcItem.Controls.Add(lbl);
          }
     }
  }
<telerik:RadComboBox ID="RadComboBox1" runat="server" CheckBoxes="true"></telerik:RadComboBox>

Hope this will be helpful.

Regards,
Plamen
Telerik
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.
0
Plamen
Telerik team
answered on 03 Jun 2013, 07:51 AM
Hello,

Actually here is the correct code behind-the previous one achieved a bit different scenario:
protected void Page_Load(object sender, EventArgs e)
   {
       Dictionary<string, List<string>> dicAnimal = new Dictionary<string, List<string>>();
      List<string> list1 = new List<string>();
      list1.Add("Dog1");
      list1.Add("Dog2");
      list1.Add("Dog3");
 
      dicAnimal.Add("Dog", list1);
 
      List<string> list2 = new List<string>();
      list2.Add("Cat1");
      list2.Add("Cat2");
      dicAnimal.Add("Cat", list2);
 
      List<string> list3 = new List<string>();
      list3.Add("Bird1");
      list3.Add("Bird2");
      list3.Add("Bird3");
      list3.Add("Bird4");
      dicAnimal.Add("Bird", list3);
 
      RadComboBoxItem rcItem = new RadComboBoxItem();
 
      foreach (string animal in dicAnimal.Keys)
      {
          rcItem = new RadComboBoxItem();
          rcItem.IsSeparator = true;
 
          rcItem.Text = animal;
          RadComboBox1.Items.Add(rcItem);
 
          if (dicAnimal[animal]!=null)
          {
                Label lbl = new Label();
              lbl.Text = animal;
              rcItem.Controls.Add(lbl);
          }
 
 
          for (int i = 0; i < dicAnimal[animal].Count; i++)
           {
             rcItem = new RadComboBoxItem();
             rcItem.Text = dicAnimal[animal][i];
              RadComboBox1.Items.Add(rcItem);
           }
      }
   }


Regards,
Plamen
Telerik
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.
Tags
ComboBox
Asked by
Tao
Top achievements
Rank 1
Answers by
Tao
Top achievements
Rank 1
Plamen
Telerik team
Share this question
or