Node Selection
When you click on a node at run time it is automatically marked as selected. If a value isn’t specified for the NavigateUrl property then clicking a node will raise the SelectedNodesChanged event to provide custom functionality. To have the nodes marked as selected without clicking them you can enable the Selected property. Multiple nodes can be selected at one time by holding down the control key while mouse clicking multiple nodes. To unselect a node, click on it again. The nodes are marked as selected in the following C1TreeView:
You can use the SelectedNodesChanged to automatically postback when a node is selected. If you need to disable postbacks, you can use the OnClientSelectedNodesChanged to raise an event when a node is selected. If the NavigateUrl property is specified for a node, then the OnClientSelectedNodesChanged or the SelectedNodesChanged wouldn’t raise.
You can use the Selected property in the code behind file to prevent it from losing its selected state when you click on a node that contains a URL link. For example, you can use the following method:
<div>
<a href="http://localhost:1196/ControlExplorer/C1TreeView/NavigateTo.aspx?Id=5">Navigate to NavigateTo</a>
</div>
<div>
<c1:C1TreeView ID="NavigateTo"
VisualStylePath = "~/C1TreeView/VisualStyles/"
AutoPostBack="True"
ShowExpandCollapse="False"
runat="server" AllowSorting="False" AutoCollapse="False"
VisualStyle="Default" Width="300px">
<Nodes>
<c1:C1TreeViewNode Text="NavigateFrom" NavigateUrl="NavigateFrom.aspx" runat="server"></c1:C1TreeViewNode>
<c1:C1TreeViewNode Text="NavigateTo" NavigateUrl="NavigateTo.aspx?Id=5" runat="server"></c1:C1TreeViewNode>
</Nodes>
</c1:C1TreeView>
</div>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim url As String = Request.Url.PathAndQuery
Dim node As C1TreeViewNode = NavigateTo.FindNodeByNavigateUrl(url)
If node IsNot Nothing Then
node.Selected = True
End If
End Sub
• C#
protected void Page_Load(object sender, EventArgs e)
{
string url = Request.Url.PathAndQuery;
C1TreeViewNode node = NavigateTo.FindNodeByNavigateUrl(url);
if(node != null)
node.Selected = true;
}
|