Use the DHTMLX Tree View
a Open source javascript library that combines well in C# Fluidly. It will produce nice tree view with images.
Its very simple to use in C# aspx page.
سؤال
I try to display Images at a node in a Treeview. The Treeview is in an ascx control cause i need it multiple times.
I use the following code:
<asp:TreeView ID="FolderTree" runat="server" BackColor="White">
<NodeStyle ForeColor="Black" ImageUrl="~/App_GlobalResources/folderClosed.png" />
<ParentNodeStyle ImageUrl="~/App_GlobalResources/folderOpen.png" />
<RootNodeStyle ImageUrl="~/App_GlobalResources/folderOpen.png" />
</asp:TreeView>
Thsi code semms to be right for me, and its also displayed right in the designer.
But when i start the page, not a single picture is shown. Only the default collapsebuttons are visible. What am i doing wrong?
Many thanks in advance.
Edit: I added the code how i populate the control
private void Page_Load(object sender, System.EventArgs e)
{
try
{
if (!Page.IsPostBack)
{
var devData = Foo.GetDevices(); // returns a list with all devices
foreach (string temp in devData)
{
this.FolderTree.Nodes.Add(new TreeNode() { Text = temp, ImageUrl = "~/App_GlobalResources/folderOpen.png" });
}
}
}
catch(Exception error)
{
//errorhandling
}
}
Edit 2: I assume i have that bug: forums.asp.net/t/943367.aspx but the suggested Solution isnt working! (see code above, i already set the value via code. Does anybody know a solution/ a hotfix (to use in an webusercontrol(.ascx))?
I also tried (on my base site):
protected override void OnSaveStateComplete(EventArgs e)
{
foreach (TreeNode tmpNode in this.LeftSelectControl.AccessFolderView.Nodes) //AccessFolderView = var, which contains the treeview of the ascx (to access it)
{
tmpNode.ImageUrl = "~/App_GlobalResources/folderOpen.png";
}
}
المحلول
Use the DHTMLX Tree View
a Open source javascript library that combines well in C# Fluidly. It will produce nice tree view with images.
Its very simple to use in C# aspx page.
نصائح أخرى
Never done the way you styled your TreeView. But this is how i style my Treeview. Hope it helps you.
<asp:TreeView ID="treeView" runat="server" NodeIndent="20" ExpandDepth="0" NodeStyle-HorizontalPadding="2"
ShowLines="true" ExpandImageUrl="../images/Open_Folder.png" CollapseImageUrl="../images/Close_Folder.png"
ForeColor="Black">
</asp:TreeView>
I found a Solution: Dont use App_GlobalResources.
I wont mark this as answer cause this was an stupid mistake by me. You can access App_* Folders only serverside, not clientside.