以下面的 web.sitemap 为例,我们想创建一个事件处理程序来捕获用户单击 ASP.Net TreeView 的“Teachers”链接时的情况。这恰好是一个父节点。
<siteMapNode title="Teachers" url="~/DefaultTeachers.aspx" >
<siteMapNode url="~/Teachers.aspx" title="Teachers" description="Maintain details of each Teacher." />
<siteMapNode url="~/TeacherSchedules.aspx" title="Teacher Schedules" description="Maintain teacher schedules." />
<siteMapNode url="~/TeacherEmailNotices.aspx" title="Email Notices To Teachers" description="Email notices to teachers." />
</siteMapNode>
你能告诉我在 ASP.Net TreeView 的标记中放置什么事件可能是这样的吗?
<asp:TreeView
id="TreeViewMain"
runat="server"
ExpandDepth="0"
OnUserClickedTheLink="TreeViewMain_UserClickedTheLink"
DataSourceID="KnowledgeAcademySiteMap">
<RootNodeStyle ImageUrl="/Images/book.png" />
<ParentNodeStyle ImageUrl="/Images/book.png" />
<LeafNodeStyle ImageUrl="/Images/book.png" />
</asp:TreeView>
同样在代码隐藏文件中,我们希望将 e.Node 或类似的东西放在“If”语句中,以测试实际单击了哪个节点:
If e.Node.Text = "Teachers" Then
' We will close all other nodes and open up the 3 leaf nodes under "Teachers" here.
'----------------------------------------------------------------------------------
End If