问题描述
嗨
我有一个树视图,其中包含以下数据,例如ex
-Asp.net
-控件
-文本框
+验证者
因此,当用户单击文本框节点时,我必须在标签中显示文本框的完整详细信息,并且该标签应仅位于文本框下方.
在此先感谢
Hi
I have a treeview with following data for ex
-Asp.net
-Controls
-Textbox
+validators
so when user clicks on the textbox node i have to show in a label the complete details of the textbox and that label should come under the textbox only.
thanks in advance
推荐答案
<asp:TreeView ID="TreeView1" runat="server"
onselectednodechanged="TreeView1_SelectedNodeChanged">
<Nodes>
<asp:TreeNode Text="TextBox" >
</asp:TreeNode>
<asp:TreeNode Text="DropdownList"></asp:TreeNode>
<asp:TreeNode Text="Button"></asp:TreeNode>
</Nodes>
</asp:TreeView>
在文件后面的代码中,您需要编写以下代码
In code behind file you need to write below code
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
showControlDetails.Visible = true;
TreeView rootview = (TreeView)sender;
Control txtchck =null;
switch (rootview.SelectedNode.Text)
{
case ("TextBox"):
txtchck = new TextBox();
break;
case ("DropdownList"):
txtchck = new DropDownList();
break;
case ("Button"):
txtchck = new Button();
break;
}
if (txtchck != null)
{
Type controlType = txtchck.GetType();
PropertyInfo[] properties = controlType.GetProperties();
foreach (PropertyInfo controlProperty in properties)
{
TreeNode tnd = new TreeNode();
tnd.Text = controlProperty.Name;
rootview.SelectedNode.ChildNodes.Add(tnd);
}
}
}
这次只是为了添加子节点
我将对其进行修改并在此处发布以显示为工具提示
并且您应该导入名称空间 System.Reflection;
在这里,我只为文本框做过操作,您可以对其进行修改以满足您的要求
我希望您知道如何将节点添加到treenode
最好的
Here this time it is just for adding sub nodes
I''ll modify it and post here to show as tooltip
And you should import namespaces System.Reflection;
Here i did only for textbox you can modify it to fulfill your requirement
and i hope you know how to add nodes to treenode
All the Best
<asp:treeview id="TreeView1" runat="server" xmlns:asp="#unknown">
<nodes>
<asp:treenode text="TextBox">
</asp:treenode>
<asp:treenode text="DropdownList"></asp:treenode>
<asp:treenode text="Button"></asp:treenode>
</nodes>
</asp:treeview>
<div id="showControlDetails1" style=" background-color:#136012; position:fixed;left:500px;top:600px; border-color:Red;">
dsfsdfsdfsdf
</div>
之后,您需要添加javascript文件
After that you need to add javascript file
这篇关于如何在树形视图中显示节点详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!