Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
25
Dynamically set the items and template of ExplorerBarItems
posted

I have a need to add items at runtime to a WebExplorerBar and the items would be user controls.  I have been able to add a group and an item however I cannot figure out how to set the template for the item to allow me to add the user control.  I don't know if I am just doing this wrong or if I am in the wrong part of the page life cycle.  I need to have multiple User controls per page and they could be the same control just being loaded from different data sources.  Any help would be great.

I am using VS 2010 and 10.1 of Infragistics asp.net controls

Here is a sample of the code I am trying:

 

 

protected void Page_Load(object sender, EventArgs e)

    {

        ExplorerBarGroup group = new ExplorerBarGroup("parameter1");

        ExplorerBarItem item = new ExplorerBarItem("CheckBoxTest");

        CheckBox chk = new CheckBox();

        chk.Text = "Test";

        ItemTemplate it = new ItemTemplate();

        it.TemplateID = "testTemplateId";

        it.Controls.Add(chk);

        WebExplorerBar1.Templates.Add(it);

        item.TemplateId = it.TemplateID;

        group.Items.Add(item);

        WebExplorerBar1.Groups.Add(group);   

    }

 

Parents
  • 3115
    Verified Answer
    Offline posted

    Hi jberg,

    If you went to set Custom Template from Code Behind you have to implement class that inherits from ITemplate and then use an instance of it to be set to your ItemTemplate. try the following in your case:

        9     protected void Page_Load(object sender, EventArgs e)

       10     {

       11         ExplorerBarGroup grpup3 = new ExplorerBarGroup("Group3");

       12         ExplorerBarItem item = new ExplorerBarItem();

       13         ItemTemplate it = new ItemTemplate();

       14         it.TemplateID = "testTemplateId";

       15         item.TemplateId = "testTemplateId";

       16         ExplorerTemplate et = new ExplorerTemplate();

       17         it.Template = et;

       18         WebExplorerBar1.Templates.Add(it);

       19         grpup3.Items.Add(item);

       20         WebExplorerBar1.Groups.Add(grpup3);

       21     }

       22     public class ExplorerTemplate : ITemplate

       23     {

       24         public void InstantiateIn(System.Web.UI.Control container)

       25         {

       26             CheckBox cb = new CheckBox();

       27             cb.ID = "testCheckBox";

       28             cb.Text = "Test";

       29             container.Controls.Add(cb);

       30         }

       31     }

     

    Hope that helps

    Thanks,

     

Reply Children
No Data