我有一个页面,里面有一个在这家公司工作的人的树目录。最初,打开节点的唯一方法是点击小+/-,但当你到达最后一级时,这个人的名字就在那里,可以点击到他们的个人简介页面。此后,我将其固定为文本也将展开节点的位置,但现在名称不再可单击。它仍然有"链接"的外观(蓝色,带下划线,悬停在上面时变为红色),但图标保持不变,不会转向手指。提前谢谢!
这是页面上的代码。。。
<%@ Control language="C#" Inherits="Modules.PeopleNav.PeopleByAlpha" CodeFile="PeopleByAlpha.ascx.cs" AutoEventWireup="true"%>
<%@ Register TagPrefix="dnn" TagName="Audit" Src="~/controls/ModuleAuditControl.ascx" %>
<asp:TreeView ID="TreeView1" runat="server" DataSourceID="XmlDataSource1"
ExpandDepth="1" onselectednodechanged="TreeView1_SelectedNodeChanged" OnTreeNodeDataBound="TreeView1_TreeNodeDataBound">
<DataBindings>
<asp:TreeNodeBinding DataMember="Person" ValueField="Value" TextField="Name">
</asp:TreeNodeBinding>
<asp:TreeNodeBinding DataMember="AlphaBreak" TextField="Name">
</asp:TreeNodeBinding>
<asp:TreeNodeBinding DataMember="PeopleAlpha" TextField="Name">
</asp:TreeNodeBinding>
</DataBindings>
</asp:TreeView><br />
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/Portals/0/Docs/PeopleAlpha.xml"></asp:XmlDataSource>
而背后的代码。。。
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
String sURL = TreeView1.SelectedNode.Value.ToString();
if (sURL.Length > 5)
{
String sExt = sURL.Substring(sURL.Length - 4, 4);
if (sExt == "aspx")
{
Response.Redirect(sURL);
}
}
}
protected void TreeView1_TreeNodeDataBound(object sender, TreeNodeEventArgs e)
{
e.Node.SelectAction = TreeNodeSelectAction.Expand;
}
我想你应该设置节点的NavigateUrl属性:
protected void TreeView1_TreeNodeDataBound(object sender, TreeNodeEventArgs e)
{
e.Node.SelectAction = TreeNodeSelectAction.Expand;
e.Node.NavigateUrl = // extract the url from your e.Node.DataItem
}
这样,我还认为您不再需要TreeView1_SelectedNodeChanged