I have a TreeView that displays checkboxes on all the leaves. It also makes the text of the leaf a link. Is there a way to disable this and only display the checkboxes and text (not link)?
Is there a way to disable this and only display the checkboxes and text (not link)?
If you want to implement it, you need to set the treenode's navigateurl. But if you had better use the sitemap for the treeview, the url is the key of the sitemapnode, if a sitemap's url is empty, the treenode is unclickable.
So I would suggest that you do like below code: For example:
Well, the SiteMap class doesn't support the display of checkboxes, correct? That is a requirement for this particular situation so it wouldn't work with SiteMap.
So, you're saying there is no inherit way to stop a treeview node from being displayed as a link?
The sitemap is used to describe the structure of the site so that the site navigation API and the site navigation controls can expose the site structure properly. By default, the site navigation system uses an XML file that contains the site hierarchy.
So the SiteMap class is an in-memory representation of the navigation structure for a site, and the navigation control through integration with the
SiteMapDataSource control to bind to hierarchical site map data. So you cannot make the sitemap support the hierarchy of the navigation control.
But you can define the custom properties for the sitemapnode in the sitemap file.
omniman
Member
11 Points
80 Posts
TreeView : Disable link on leaves
Jan 10, 2008 07:44 PM|LINK
I have a TreeView that displays checkboxes on all the leaves. It also makes the text of the leaf a link. Is there a way to disable this and only display the checkboxes and text (not link)?
Thank you.
Amanda Wang ...
All-Star
30008 Points
3104 Posts
Re: TreeView : Disable link on leaves
Jan 14, 2008 04:39 AM|LINK
Hi,
If you want to implement it, you need to set the treenode's navigateurl. But if you had better use the sitemap for the treeview, the url is the key of the sitemapnode, if a sitemap's url is empty, the treenode is unclickable.
So I would suggest that you do like below code: For example:
<asp:TreeView ID="TreeView1" runat="server" Font-Underline="False" NodeIndent="0"
Width="150px" ShowCheckBoxes="Leaf" ShowLines="True" >
<Nodes>
<asp:TreeNode Expanded="True" SelectAction="Expand" ShowCheckBox="False" Text="Components"
Value="Components">
<asp:TreeNode Text="Processor" Value="Processor"></asp:TreeNode>
<asp:TreeNode Text="Memory" Value="Memory" Expanded="False" SelectAction="Expand">
<asp:TreeNode Text="New Node" Value="New Node"></asp:TreeNode>
<asp:TreeNode Text="New Node" Value="New Node"></asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="Mother Boards" Value="Mother Boards"></asp:TreeNode>
<asp:TreeNode Text="Power Supplies" Value="Power Supplies"></asp:TreeNode>
<asp:TreeNode Text="Video Cards" Value="Video Cards"></asp:TreeNode>
<asp:TreeNode Text="Hard Disks" Value="Hard Disks"></asp:TreeNode>
<asp:TreeNode Text="Optical" Value="Optical"></asp:TreeNode>
<asp:TreeNode Text="Sound Cards" Value="Sound Cards"></asp:TreeNode>
<asp:TreeNode Text="Cases" Value="Cases"></asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="Peripherarls" Value="Peripherarls">
<asp:TreeNode Text="New Node" Value="New Node"></asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="Cooling & Modding"
Value="Cooling & Modding">
<asp:TreeNode Text="New Node" Value="New Node"></asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
Hope it helps.
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
omniman
Member
11 Points
80 Posts
Re: TreeView : Disable link on leaves
Jan 14, 2008 06:56 PM|LINK
Well, the SiteMap class doesn't support the display of checkboxes, correct? That is a requirement for this particular situation so it wouldn't work with SiteMap.
So, you're saying there is no inherit way to stop a treeview node from being displayed as a link?
Amanda Wang ...
All-Star
30008 Points
3104 Posts
Re: TreeView : Disable link on leaves
Jan 15, 2008 02:38 AM|LINK
Hi,
The sitemap is used to describe the structure of the site so that the site navigation API and the site navigation controls can expose the site structure properly. By default, the site navigation system uses an XML file that contains the site hierarchy.
So the SiteMap class is an in-memory representation of the navigation structure for a site, and the navigation control through integration with the SiteMapDataSource control to bind to hierarchical site map data. So you cannot make the sitemap support the hierarchy of the navigation control.
But you can define the custom properties for the sitemapnode in the sitemap file.
for example:
1. add the custom propery for the sitemapnode:
<siteMapNode title="Hardware" url="~/Menu/Cases/Cases/twomenu/Default.aspx?node=hardware" checked="true">
2. Check the custom property in the TreeNodeDataBound event of the treeview in the codebehind
protected void TreeView1_TreeNodeDataBound(object sender, TreeNodeEventArgs e)
{
SiteMapNode smn = (SiteMapNode)e.Node.DataItem;
if (smn["checked"] != null)
{
e.Node.ShowCheckBox = true;
if (smn["checked"] == "true")
{
e.Node.Checked = true;
}
else
{
e.Node.Checked = false;
}
}
}
;If you do not want to make the treenode diaplay as a link, you can set its selectaction is none.
for example:
protected void TreeView1_TreeNodeDataBound(object sender, TreeNodeEventArgs e)
{
if (e.Node.Text == "Harware")
{
e.Node.SelectAction = TreeNodeSelectAction.None;
}
}
Hope it helps.
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
omniman
Member
11 Points
80 Posts
Re: TreeView : Disable link on leaves
Jan 16, 2008 05:33 PM|LINK
Thank you, setting the SelectAction worked perfectly!
Mike.Borozdi...
Member
166 Points
65 Posts
Re: TreeView : Disable link on leaves
Aug 10, 2008 01:23 PM|LINK
Hello,
For some reasons setting SelectAction to None in the TreeNodeDataBound event doesn't help.
However since I populate the tree from the database, I set SelectAction to None when creating Nodes in Page_Load() and it works.