Rank: Newbie Groups: Member
Joined: 6/15/2007 Posts: 8
|
Hello,
Any info on how to get the CustomItem working in a dynamically built tree? We haven't been successful doing it from the code and data binding isn't really a solution for us in this situation.
If we throw one on the aspx page, it will work for the first item that uses it, but creating it in the code behind doesn't even work for this...We'll need to dynamically create quite a few.
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Hi,
That is not easy. :) The CustomItem is pretty designed to work declaratively instead of programmatically. It is possible to use it this way:
1. In your Page_Init or Page_Load, create one or more CustomItem object; 2. Add them into a container. Do NOT add them directly to the Page.Controls. That will not work. Try put a Panel in the form and then add them into a panel; 3. While you create TreeView, assign the ID of the dynamically created CustomItem to the CustomItemID property of your TreeNode;
Usually you want to do the first step in Page_Init so that view state can work correctly. You may also want to attach event handlers on controls in the custom item. One more thing to watch out is do NOT put the code inside a "if (!Page.IsPostBack)" condition. The code that dynamically creates CustomItems will need to executed every time.
Creating CustomItem object at other stage of the page cycle is possible but not recommended since CustomItem is very closely tight to the full page rendering cycle.
|