开发者

Selected node changed

开发者 https://www.devze.com 2022-12-09 17:51 出处:网络
I have a treeview like this and I want to navigate to three different pages using Response.Redirect. → machine groups (main)

I have a treeview like this and I want to navigate to three different pages using Response.Redirect.

→ machine groups (main)

→→ dept (parent)

→→→ xyz (child)

protected void TreeView2_SelectedNodeChanged(object sender, EventArgs e)
{
    if (TreeView2.SelectedValue == "Machine Groups")
    {
        Response.Redirect("~/Gridviewpage.aspx");
    }
    else
    {开发者_JS百科
        switch (e.Node.Depth)
        {
            case 0:
                Response.Redirect("~/Machineupdate.aspx?node=" + TreeView2.SelectedNode.Value);
                break;

            case 1:
                Response.Redirect("~/MachineUpdatechild.aspx?node=" + TreeView3.SelectedNode.Value);
                break;
            }
        }
    }
}
    

now if I put EventArgs it points to an error on e.Node that System.EventArgs does not contain definition for Node.

If i replace EventArgs with TreeNodeEventArgs, then that error goes away but I get an error on compilation:

Compiler Error Message: CS0123: No overload for 'TreeView2_SelectedNodeChanged' matches delegate 'System.EventHandler'

<asp:TreeView ID="TreeView2" runat="server"  OnUnload="TreeViewMain_Unload" 
    ontreenodepopulate="TreeView2_TreeNodePopulate" 
    onselectednodechanged="TreeView2_SelectedNodeChanged">
    <Nodes>
        <asp:TreeNode PopulateOnDemand="True" Text="Machine Groups"
            Value="Machine Groups"></asp:TreeNode>
    </Nodes>
</asp:TreeView>

Please help me out.

I would also like to know what is the difference between EventArgs and TreeNodeEventArgs.

Thanks.


So, this looks like one of those poor API issues... I would think it reasonable to pass more specific event args here too!

One thing to look at is instead of trying to get the selected node from the event args, try doing the switch on the selected node with TreeView2.SelectedNode.

It looks like you were halfway there already, because you are using that proprerty later on. So, I don't know if there might be an issue you've already found with that but don't mention itabove.


Had a similar problem, I had it working before using TreeNodeEventArgs, but you can get away with doing EventArgs and then just yourTreeView.SelectedNode depending on what you have to do...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号