|
Rank: Member Groups: Member
Joined: 3/19/2008 Posts: 14
|
Hi, I'm trying to create CustomItem in runtime but can't get it to work. My code looks pretty much like this:
Code: HTML/ASPX
<eo:TreeView runat="server" id="TreeView1" ControlSkinID="None" Width="500px"
AllowDragDrop="True" AllowEdit="True"
OnItemRenamed="TreeView1_ItemRenamed"
OnItemMoved="TreeView1_ItemMoved"
CausesValidation="false">
<LookNodes>
...
</LookNodes>
</eo:TreeView>
Code: C#
private void ReloadMenu()
{
DataSet mainDs = FileCategoryFacad.GetFileCategoryDataSetByList(fccList, true);
TreeView1.DataSource = mainDs;
EO.Web.DataBinding bindingName = new EO.Web.DataBinding();
bindingName.DataField = "Name";
bindingName.Property = "Text-Html";
TreeView1.Bindings.Add(bindingName);
EO.Web.DataBinding bindingId = new EO.Web.DataBinding();
bindingId.DataField = "Id";
bindingId.Property = "ItemID";
TreeView1.Bindings.Add(bindingId);
TreeView1.ItemDataBound += new NavigationItemEventHandler(TreeView1_ItemDataBound);
TreeView1.DataBind();
}
private void TreeView1_ItemDataBound(object sender, NavigationItemEventArgs e)
{
int fccId = int.Parse(e.TreeNode.ItemID);
CustomItem customItem = new CustomItem();
customItem.ID = "customItemId_" + fccId.ToString();
Literal ltlText = new Literal();
ltlText.Text = "test";
customItem.Controls.Add(ltlText);
EO.Web.TreeNode subNode = new EO.Web.TreeNode();
subNode.Text = "customItem_Holder_" + customItem.ID;
subNode.LookID = "None";
subNode.LineImageUrl = "Blank";
subNode.CustomItemID = customItem.ID;
e.TreeNode.SubGroup.Nodes.Add(subNode);
}
I believe I do as in your documentation but probably not because I'm expecting all rows to get a subnode with the text "test". But I don't. the result looks like this: http://www.jimmie.nu/files/treeView.jpgthanks Jimmie
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
CustomItemID refers to a CustomItem object that already exists in the page. In your case you only created it but without adding it to the page, so it will not work.
If you are only adding Literals to the TreeNode, then you do not need CustomItem at all, you can simply set the TreeNode's Html to your HTML literals.
Thanks!
|
|
Rank: Member Groups: Member
Joined: 3/19/2008 Posts: 14
|
Hi!
thank you for a quick replay!
The example with the literal is only for test, I will use more advanced controls later.
Ok but how do I add the CustomItem to the page on the run? Is there a way to get this work easy?
Thanks again
Best regards Jimmie
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
You would just place a container control (for example, a Panel) in the page and then call Panel1.Controls.Add(something) to add it.
If you are not already very familiar with dynamic control creation, you may want to avoid this because there are a row of other issues related to dynamic control creation such as view state and server event. View state and server event works automatically with static controls because they are always there, but if you create your controls dynamically, the situation is much more complicated. For this reason, we recommend you to use CustomItem declaratively instead of programmatically. If you absolutely have to use it programmatically, using simple HTML literals will be easier for you because without view state and server event, there isn't much difference between a server control and simple HTML. In another word, CustomItem has little advantage over raw HTML in this case.
Thanks
|
|
Rank: Member Groups: Member
Joined: 3/19/2008 Posts: 14
|
Thanks again! the Panel-thing did it! =) But I didn't solve the problem I first encountered. If I show you what I want to do, maybe you can help me with the best solution :) I want be able to select and rename a nodes name. thats normally no problem but I also want a second column with a image and a hyperlink. the second column should not be selected when click on node namn. Please take a look at the following image (fixed in photoshop) to understand what I'm looking for: http://www.jimmie.nu/files/treeViewColumns.jpgis this possible? thanks again! Jimmie
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
No. That is not possible. The node is always selected a whole. Sorry about that!
|
|