dynamically add multiple header templates

6 posts, 0 answers
  1. Tao
    Tao avatar
    13 posts
    Member since:
    Jun 2012

    Posted 22 May 2013 Link to this post

    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
  2. Tao
    Tao avatar
    13 posts
    Member since:
    Jun 2012

    Posted 22 May 2013 Link to this post

    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!

  3. Plamen
    Admin
    Plamen avatar
    2959 posts

    Posted 27 May 2013 Link to this post

    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.
  4. Tao
    Tao avatar
    13 posts
    Member since:
    Jun 2012

    Posted 28 May 2013 Link to this post

    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);
               }
           }
     
  5. Plamen
    Admin
    Plamen avatar
    2959 posts

    Posted 03 Jun 2013 Link to this post

    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.
  6. Plamen
    Admin
    Plamen avatar
    2959 posts

    Posted 03 Jun 2013 Link to this post

    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.
Back to Top