SelectedNodeChange System.Web.UI.WebControls.treeview未触发

时间:2015-11-20 15:45:16

标签: c# asp.net treeview

我从上面的命名空间派生了一个控件来合并一个对象标签,因为上面似乎没有这个。

在我的代码中,我填充树控件并设置选择项。但是没有事件被解雇......

<PulmanGroup:PulmanTreeControl ID="FileContentsTreeView" runat="server"                         EnableTheming="True" CssClass="AspNet-TreeView" display="block" right="400px" ImageSet="Simple" NodeIndent="30" ShowLines="True" ViewStateMode="Enabled" onselectednodechanged="FileContentsTreeView_SelectedNodeChanged" PopulateNodesFromClient="False"> <HoverNodeStyle Font-Underline="True" runat="server"/>
<LeafNodeStyle CssClass=".AspNet-TreeView-Leaf" runat="server"/><NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" NodeSpacing="0px" VerticalPadding="0px" runat="server"/> <ParentNodeStyle Font-Bold="False" CssClass="AspNet-TreeView-Parent" runat="server"/><RootNodeStyle CssClass="AspNet-TreeView-Root " runat="server"/><SelectedNodeStyle Font-Underline="True" VerticalPadding="0px" CssClass="SelectedStyle" Height="20px" runat="server" /></PulmanGroup:PulmanTreeControl>

我尝试使用“PopulateNodesFromClient”确保回发为false。 我还使用下面的代码在每个节点上实际设置了select操作。

    protected void FileContentsTreeView_Load(object sender, EventArgs e)
            {
                if(File_Hash.type==0)
                    throw new Exception("Something's wrong");

                PulmanTreeNode rnode = new PulmanTreeNode();
                rnode.Text = File_Hash.text; //Sets the root......
                FileContentsTreeView.Nodes.Add(rnode);
                rnode.NavigateUrl = "";
                rnode.SelectAction = TreeNodeSelectAction.Select;
                foreach(BudgetObject bd in ((BudgetObjectContainer)File_Hash).BusinessObjects)
                {
                    PulmanTreeNode pnode = new PulmanTreeNode();
                    rnode.ChildNodes.Add(pnode);
                    pnode.Tag = bd;
                    pnode.Text = bd.text;
                    pnode.SelectAction = TreeNodeSelectAction.Select;
                    pnode.NavigateUrl = "";
                    if (bd.type ==2 || bd.type == 3 ) // Is a parent.
                        FileContentsRecursiveTreeView_Load(sender, e, pnode, ((BudgetObjectContainer)bd)); 

                }
                FileContentsTreeView.CollapseAll();
            }

        protected void FileContentsRecursiveTreeView_Load(object sender, EventArgs e, TreeNode TreeContainer, BudgetObjectContainer boc)
        {
            foreach (BudgetObject bd in boc.BusinessObjects)
            {
                PulmanTreeNode pnode = new PulmanTreeNode();

                pnode.Expanded = false;
                pnode.Text = bd.text;
                pnode.Tag = bd;
                pnode.SelectAction = TreeNodeSelectAction.Select;
                pnode.NavigateUrl = "";
                TreeContainer.ChildNodes.Add(pnode);
                if (bd.type == 2 || bd.type == 3) // Is a parent.
                    FileContentsRecursiveTreeView_Load(sender, e, pnode, ((BudgetObjectContainer)bd));
            }
        }
protected void FileContentsTreeView_SelectedNodeChanged(object sender, EventArgs e)
        {
            PulmanTreeNode node = (PulmanTreeNode)FileContentsTreeView.SelectedNode;

            BudgetObject bo = (BudgetObject)node.Tag;

            StatusLabel.Text = bo.text + " " + node.Text;

            return;
        }

但是,我似乎无法让事件发生。我的自定义控件使用视图状态,当我点击一个项目时重新填充,所以我知道回发和视图状态正在发生,我确保navigateURL是空的,但即使发出这行代码,事件仍然不会触发... < / p>

同样,我还进行了一项测试,其中我使用的是标准树视图,其中节点从设计器中填充,并且没有事件被触发....

非常感谢任何帮助。

- - - - - - - - - - - - - - - - - - 更新

因此,尽管在树控件上没有触发任何事件,但仍会发出回发请求。 我调试了代码,发现所选节点都为空,值为空字符串。尽管如此 - CSS仍然突出了选定的条目....所以发生了一些事情,但我不知道是什么。

根据要求 - 这是CSS,唯一不能用它的部分是hide。然而,这是化妆品,html似乎很好。

我的控件继承的唯一两个成员是:

  protected override object SaveViewState()
        {
            object[] arrState = new object[2];
            arrState[1] = base.SaveViewState();
            //arrState[0] = this._data;
            arrState[0] = this.Tag;
            return arrState;
        }

    protected override void LoadViewState(object state)
    {
        object[] arrState = state as object[];

        //this._data = ((BudgetObject)arrState[0]);
        this.Tag = arrState[0];
        base.LoadViewState(arrState[1]);
    }

生成的html如下所示:

<li class="AspNet-TreeView-Parent">
                                    <span class="AspNet-TreeView-Expand" onclick="ExpandCollapse__AspNetTreeView(this)">&nbsp;</span>
                                    <a href="javascript:__doPostBack('ctl00$Content$FileContentsTreeView','sRoot\\NEW RETAIL\\ Gross Profit')">
                                         Gross Profit</a>
                                    <ul class="AspNet-TreeView-Hide">
                                        <li class="AspNet-TreeView-Leaf">
                                            <a href="javascript:__doPostBack('ctl00$Content$FileContentsTreeView','sRoot\\NEW RETAIL\\ Gross Profit\\ Retail')">
                                                 Retail</a>
                                        </li>
                                        <li class="AspNet-TreeView-Leaf">
                                            <a href="javascript:__doPostBack('ctl00$Content$FileContentsTreeView','sRoot\\NEW RETAIL\\ Gross Profit\\ Dealer Installed Accessories')">
                                                 Dealer Installed Accessories</a>
                                        </li>
                                        <li class="AspNet-TreeView-Leaf">
                                            <a href="javascript:__doPostBack('ctl00$Content$FileContentsTreeView','sRoot\\NEW RETAIL\\ Gross Profit\\ Delivery')">
                                                 Delivery</a>
                                        </li>
                                        <li class="AspNet-TreeView-Leaf">
                                            <a href="javascript:__doPostBack('ctl00$Content$FileContentsTreeView','sRoot\\NEW RETAIL\\ Gross Profit\\ F&amp;&amp;I Commission')">
                                                 F&&I Commission</a>
                                        </li>
                                        <li class="AspNet-TreeView-Leaf">
                                            <a href="javascript:__doPostBack('ctl00$Content$FileContentsTreeView','sRoot\\NEW RETAIL\\ Gross Profit\\ Finance Volume Bonus')">
                                                 Finance Volume Bonus</a>
                                        </li>
                                        <li class="AspNet-TreeView-Leaf">
                                            <a href="javascript:__doPostBack('ctl00$Content$FileContentsTreeView','sRoot\\NEW RETAIL\\ Gross Profit\\ Retail Sales Bonus')">
                                                 Retail Sales Bonus</a>
                                        </li>
                                        <li class="AspNet-TreeView-Leaf">
                                            <a href="javascript:__doPostBack('ctl00$Content$FileContentsTreeView','sRoot\\NEW RETAIL\\ Gross Profit\\ Other Income')">
                                                 Other Income</a>
                                        </li>
                                        <li class="AspNet-TreeView-Leaf">
                                            <a href="javascript:__doPostBack('ctl00$Content$FileContentsTreeView','sRoot\\NEW RETAIL\\ Gross Profit\\ Total New Gross Profit')">
                                                 Total New Gross Profit</a>
                                        </li>
                                    </ul>

0 个答案:

没有答案