如何在C#中获取RadTreeView中单击节点的文本?我添加了OnNodeClick事件,但它没有触发。请告诉我如何在C#中获取被点击节点的文本。
ASP.NET:
<telerik:RadTreeView ID="CandidatesTreeMenu" OnClientNodeClicked="ClientCandidateMenuNodeClicked" Skin="Vista" runat="server" OnNodeClick="CandidatesTreeMenu_NodeClick">
<Nodes>
<telerik:RadTreeNode Text="Added" NavigateUrl="NewCandidateList.aspx?type=recently">
</telerik:RadTreeNode>
<telerik:RadTreeNode Text="Candidates" NavigateUrl="NewCandidateList.aspx?type=My">
</telerik:RadTreeNode>
</Nodes>
</telerik:RadTreeView>
代码背后:
protected void CandidatesTreeMenu_NodeClick(object sender, RadTreeNodeEventArgs e)
{
try
{
string CheckNodeName = e.Node.Text;
}
catch { }
}
答案 0 :(得分:1)
您需要在用户控制page_load事件中重新绑定每个帖子。 这里是我在ascx中使用的代码:
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
CandidatesTreeMenu.NodeClick += CandidatesTreeMenu_NodeClick;
}
protected void CandidatesTreeMenu_NodeClick(object sender, RadTreeNodeEventArgs e)
{
string CheckNodeName = e.Node.Text;
}
</script>
<telerik:RadScriptBlock runat="server">
<script type="text/javascript">
function ClientCandidateMenuNodeClicked(sender, args) {
// noop
}
</script>
</telerik:RadScriptBlock>
<telerik:RadTreeView ID="CandidatesTreeMenu" OnClientNodeClicked="ClientCandidateMenuNodeClicked" Skin="Vista" runat="server">
<Nodes>
<telerik:RadTreeNode Text="Added" NavigateUrl="NewCandidateList.aspx?type=recently">
</telerik:RadTreeNode>
<telerik:RadTreeNode Text="Candidates" NavigateUrl="NewCandidateList.aspx?type=My">
</telerik:RadTreeNode>
</Nodes>
</telerik:RadTreeView>