TreeView width ASP.NET V2 – Whidbey
[20 mn de lecture - paru le 11/17/2004 3:27:26 PM - Public : Débutant]
|
   
|
Auteur
2. Basic using from TreeView
2.1. Simple TreeView
Now that you can handle Control, we will discover in this chapitre les various
events of this control.
Edit TreeView
>Client1
>>Dossier1
>>>>Facture1
>>>>Facture2
>>Dossier2
>>>>Facture1
>>>>Facture2
>Client2
>>Dossier1
>>Dossier2
You must obtain :
|
<asp:TreeView ID="TreeView1" ExpandDepth="0" Runat="Server"
ShowLines="True">
<Nodes>
<asp:TreeNode Value="Marque 1" Expanded="True" Text="Client
1">
<asp:TreeNode Value="Dossier 1"
Expanded="True" Text="Dossier 1">
<asp:TreeNode
Value="Facture 1" Text="Facture 1">
</asp:TreeNode>
<asp:TreeNode
Value="Facture 1" Text="Facture 2">
</asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Value="Dossier 2" Text="Dossier
2">
</asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Value="Marque 2" Expanded="True"
Text="Client 2">
<asp:TreeNode Selected="True"
Value="Dossier 1" Text="Dossier 1">
</asp:TreeNode>
<asp:TreeNode Value="Dossier 2"
Text="Dossier 2">
</asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
|
After debug.

2.2. Event SelectedNodeChanged
The architecture of your TreeView is drawn. We now will create an event with
each clicks.
To slip a Label into the Design mode.
To select controls it TreeView, in the properties click on Events
.

You arrive in the properties of control. Double clicked on in the
SelectNodeChanged box. You must arrive directly in code-behind.

The event is to create. We will post the text contained in
the selectionné node.
void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
Label1.Text = TreeView1.SelectedNode.Text;
}
|
In your treeView you must have a property moreover :
<asp:TreeView
ID="TreeView1"
ExpandDepth="0"
OnSelectedNodeChanged="TreeView1_SelectedNodeChanged"
Runat="Server" ShowLines="True">
|
2.3. Event TreeNodeCollapsed
If you wish to set up an event with each time the node of TreeView is closed
again, you must follow the same principle as above, but in double clicking
on the TreeNodeCollapsed event.
2.4. Event TreeNodeExpanded
If you wish to set up an event with each time the node of TreeView is spread,
you must follow the same principle as above, but in double clicking on the
TreeNodeExpanded event.
|