Det virker som sådan - jeg skal bare trykke to gange, for at få det til at virke......hver gang - og det bliver folk jo trætte af....
Du får koden:
Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<html xmlns="
http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
Test af menustruktur<br />
<br />
<br />
<br />
<asp:TreeView ID="TreeView1" runat="server" OnSelectedNodeChanged="TreeView1_SelectedNodeChanged"
ShowExpandCollapse="False">
<Nodes>
<asp:TreeNode Expanded="False" PopulateOnDemand="True" SelectAction="SelectExpand"
Text="Heste" Value="Heste">
<asp:TreeNode Text="Føl 1" Value="Føl 1"></asp:TreeNode>
<asp:TreeNode Text="Føl 2" Value="Føl 2"></asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Expanded="False" PopulateOnDemand="True" SelectAction="SelectExpand"
Text="Hunde" Value="Hunde">
<asp:TreeNode Text="Hvalpe 1" Value="Hvalpe 1"></asp:TreeNode>
<asp:TreeNode Text="Hvalpe 2" Value="Hvalpe 2"></asp:TreeNode>
<asp:TreeNode Text="Hvalpe 3" Value="Hvalpe 3"></asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
<br />
</div>
</form>
</body>
</html>
Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
if (TreeView1.SelectedNode.Expanded == true)
{
TreeView1.SelectedNode.CollapseAll();
}
else
{
TreeView1.SelectedNode.ExpandAll();
}
}
}