Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何确定TreeView.SelectedNode是父节点还是子节点_C#_Asp.net_Events_Triggers_Treeview - Fatal编程技术网

C# 如何确定TreeView.SelectedNode是父节点还是子节点

C# 如何确定TreeView.SelectedNode是父节点还是子节点,c#,asp.net,events,triggers,treeview,C#,Asp.net,Events,Triggers,Treeview,我的ASP.NET web应用程序中有一个TreeView控件,我对所选节点的事件更改有问题,我单击了TreeView中的某个节点但事件没有触发,我在那里有一些未执行的指令,我还使用调试器进行了检查 <asp:TreeView ID="ArboreSarcini" runat="server" ImageSet="News" onselectednodechanged="ArboreSarcini_SelectedNodeChanged" NodeIndent="10" style="

我的ASP.NET web应用程序中有一个TreeView控件,我对所选节点的事件更改有问题,我单击了TreeView中的某个节点但事件没有触发,我在那里有一些未执行的指令,我还使用调试器进行了检查

<asp:TreeView ID="ArboreSarcini" runat="server" ImageSet="News" 
onselectednodechanged="ArboreSarcini_SelectedNodeChanged" NodeIndent="10" 
style="z-index: 1; left: 1px; top: 27px; position: absolute; height: 308px; width: 446px">
<HoverNodeStyle Font-Underline="True" BackColor="#99CCCC" Font-Size="12pt" />
<LeafNodeStyle ImageUrl="~/Poze/leaf.png" NodeSpacing="2px" />
<LevelStyles>
<asp:TreeNodeStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" 
Font-Names="Leelawadee" Font-Size="Medium" Font-Underline="False" 
ImageUrl="~/Poze/Root.png" />
<asp:TreeNodeStyle BorderColor="#003300" BorderStyle="Solid" BorderWidth="1px" 
Font-Names="Leelawadee" Font-Underline="False" ImageUrl="~/Poze/node.png" 
Width="400px" />
<asp:TreeNodeStyle BorderColor="#006600" BorderStyle="Solid" BorderWidth="1px" 
Font-Names="Leelawadee" Font-Underline="False" Height="10px" 
ImageUrl="~/Poze/leaf.png" Width="390px" />
</LevelStyles>
<NodeStyle Font-Names="Leelawadee" Font-Size="10pt" ForeColor="Black" 
HorizontalPadding="5px" NodeSpacing="2px" VerticalPadding="0px" 
ImageUrl="~/Poze/node.png" Width="0px" />
<ParentNodeStyle Font-Bold="False" Width="500px" />
<RootNodeStyle ImageUrl="~/Poze/Root.png" />
<SelectedNodeStyle Font-Underline="False" BackColor="#009148" BorderWidth="2px" 
Font-Bold="False" Font-Italic="True" Font-Size="12pt" />
</asp:TreeView>
默认情况下,TreeView控件句柄扩展折叠功能 除非浏览器不支持客户端脚本或 EnableClientScript属性设置为false。如果 PopulateNodesFromClient属性设置为true,浏览器 支持客户端脚本,然后TreeView控件检索数据 从服务器返回,而不回发整个页面

当TreeView控件处于选择模式时,每次 单击一个节点,将发生回发到服务器的操作,然后 已引发SelectedNodeChanged事件

通常,当TreeView控件 处于选择模式或正在动态填充节点。 这是因为PopulateOnDemand或PopulateNodeFromClient 属性设置为true

因此,请验证您是否设置了所有必需的属性。共享您的HTML可能会有所帮助。 阅读有关asp.net树视图的更多信息 节点属性。 获取分配给当前树节点的TreeNode对象的集合


如何填充树?也许你在每次回发中都会这样做。你有代码给我们看吗?是的,如果它有点混乱,很抱歉如果你把断点放在
树上,它是否会击中
树Arcini_SelectedNodeChanged
事件?是的,谢谢,我尝试过使用方法中较低的断点,看起来好像触发了te事件,我的如果(ArboreSarcini.SelectedNode.ImageUrl=“~/Poze/node.png”)阻止执行以下代码,我的坏,对不起,谢谢,但我有下一个问题,我如何确定单击的是父节点还是子节点(我有父节点没有子节点的情况)我想我发现了问题所在,事件被触发了,但是,我的其他指令阻止了以下代码,并且我已经用代码中的断点太低来消除错误,谢谢!虽然我看不到你的图像,但很好的信息。因为我的办公室有一些限制。所以代码可能对理解非常有帮助。我已经提供了所有的代码…现在s之前,它没有出现?我想知道为什么你还在问代码…你能提供代码吗,类似于你提供html的方式。由于我办公室的一些限制,我无法看到图像树视图的所有代码现在都更新了(触发为SelectedNodeChanged填充treeview、HTML代码和eventhandler的按钮)
protected void Button1_Click(object sender, EventArgs e)
{
ArboreSarcini.Nodes.Clear();
populeaza_sarcini();

string sqlstring1 = "Select * from activitati";
System.Data.SqlClient.SqlConnection con1 = new System.Data.SqlClient.SqlConnection(
            "Data Source=BOGDAN-PC\\BOGDAN;Initial Catalog=ePlanning;Integrated Security=SSPI;Connect Timeout=10;TrustServerCertificate=True ");
System.Data.SqlClient.SqlCommand comm1 = new System.Data.SqlClient.SqlCommand(sqlstring1, con1);
System.Data.SqlClient.SqlDataReader reader1;
con1.Open();
reader1 = comm1.ExecuteReader();

while (reader1.Read())
{
foreach (Sarcina s in listaSarcini)
{
    if ((int)reader1["id_sarcina"] == s.Id_sarcina)
    {
        s.ListaActivitati.Add(new Activitate(Convert.ToInt32(reader1["id_activitate"]), reader1["descriere"].ToString()));
    }
}
}

TreeNode tatal = new TreeNode();
tatal.Value = DropListProiecte.SelectedItem.ToString();
//    ArboreSarcini.Nodes.Add(tatal);


TreeNode parentNode = new TreeNode();
foreach (Sarcina sarc in listaSarcini)
{
parentNode = new TreeNode( sarc.Id_sarcina.ToString() + ". " + sarc.Descriere.ToString());


foreach (Activitate act in sarc.ListaActivitati)
{
    TreeNode copil = new TreeNode(act.Id_activitate.ToString()+". "+act.Descriere.ToString() );
    parentNode.ChildNodes.Add(copil);
}
tatal.ChildNodes.Add(parentNode);
//parentNode.Collapse();


}
ArboreSarcini.Nodes.Add(tatal);
con.Close();
ArboreSarcini.ExpandAll();
}


    protected void ArboreSarcini_SelectedNodeChanged(object sender, EventArgs e)
{

    if (ArboreSarcini.SelectedNode.ImageUrl == "~/Poze/node.png")
    {

        System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(
                      "Data Source=BOGDAN-PC\\BOGDAN;Initial Catalog=ePlanning;Integrated Security=SSPI;Connect Timeout=10;TrustServerCertificate=True ");
        //  string de_splituit = ArboreSarcini.SelectedNode.Text;
        string[] id_sarcina = ArboreSarcini.SelectedNode.Text.Split('.');


        string sqlstring = "Select * from sarcini where id_sarcina=" + id_sarcina[0] + ";";




        System.Data.SqlClient.SqlCommand comm = new System.Data.SqlClient.SqlCommand(sqlstring, con);
        System.Data.SqlClient.SqlDataReader reader;

        con.Open();
        reader = comm.ExecuteReader();
        while (reader.Read())
        {
            tbIDSarcina.Text = reader["id_sarcina"].ToString();
        }
    }
}