Ext.Net TreePanel节点选择未显示或可见

时间:2011-11-11 09:45:30

标签: c# asp.net ext.net

<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:Window ID="UploadWindow" IDMode="Client" runat="server" Width="550" AutoHeight="true"
    Title="Upload a File">
    <Items>
        <ext:Panel ID="Panel1" runat="server" LabelWidth="200" ButtonAlign="Left" Padding="10" Layout="FormLayout">
            <Items>
                <ext:FileUploadField ID="FileUploadField1" runat="server" FieldLabel="Please browse a file to upload"
                    ButtonOnly="false" Width="300" />
                <ext:TreePanel ID="FolderTree" runat="server" Height="200" UseArrows="true" FieldLabel="Please select a directory"
                    AutoScroll="true" Animate="true" EnableDD="true" ContainerScroll="true" RootVisible="false">
                </ext:TreePanel>
            </Items>
            <Buttons>
                <ext:Button ID="Button1" runat="server" Text="Upload" />
            </Buttons>
        </ext:Panel>
    </Items>
</ext:Window>

嗨,除了鼠标点击(单击或双击)和键盘导航中的“所选节点没有突出显示”外,一切正常并且正常。

修改

填充treenode的代码隐藏是

protected void Page_Load(object sender, EventArgs e)
{
    Ext.Net.TreeNode root = this.CreateNode(SiteMap.RootNode);
    root.Draggable = false;
    root.Expanded = true;
    FolderTree.Root.Add(root);
    FolderTree.ExpandAll();
}

/// <summary>
/// Creates nodes from sitemap data
/// </summary>
/// <param name="siteMapNode">Pass the root node of Web.sitemap</param>
/// <returns></returns>
private Ext.Net.TreeNode CreateNode(SiteMapNode siteMapNode)
{
    Ext.Net.TreeNode treeNode = new Ext.Net.TreeNode();
    treeNode.NodeID = siteMapNode.Key;
    treeNode.Text = siteMapNode.Title;
    treeNode.Qtip = siteMapNode.Description;
    //treeNode.Href = siteMapNode.Url;
    treeNode.Icon = this.GetIcon(siteMapNode["menuId"].ToString(new CultureInfo("en-Us")));
    string iconCls = GetIconCls(treeNode.Icon);

    //System.Windows.Forms.MessageBox.Show(iconCls);
    treeNode.Listeners.Click.Handler = string.Format(new CultureInfo("en-US"), "#{{MainPanel}}.load('{0}');#{{MainPanel}}.setIconClass('{1}');#{{MainPanel}}.setTitle('{2}');", siteMapNode.Url, iconCls, siteMapNode.Title);

    SiteMapNodeCollection children = siteMapNode.ChildNodes;
    if (children != null && children.Count > 0)
    {
        foreach (SiteMapNode mapNode in siteMapNode.ChildNodes)
        {
            treeNode.Nodes.Add(this.CreateNode(mapNode));
        }
    }
    return treeNode;
}

private string GetIconCls(Ext.Net.Icon icon)
{
    string iconCls = this.ResourceManager1.GetIconClass(icon);
    int pos = iconCls.IndexOf("{", StringComparison.OrdinalIgnoreCase);
    return iconCls.Substring(1, pos - 1);
}

谢谢你和问候。

2 个答案:

答案 0 :(得分:1)

我将您的代码用于examples.ext.net中的节点。一切都很好。你能说明你如何设置树的节点吗?你正在使用什么版本的Ext.NET?

<ext:ResourceManager ID="ResourceManager1" runat="server" />

<form id="Form1" runat="server">
    <ext:Window ID="UploadWindow" IDMode="Client" runat="server" Width="550" AutoHeight="true"
        Title="Upload a File">
        <Items>
            <ext:Panel ID="Panel1" runat="server" LabelWidth="200" ButtonAlign="Left" Padding="10" Layout="FormLayout">
                <Items>
                    <ext:FileUploadField ID="FileUploadField1" runat="server" FieldLabel="Please browse a file to upload"
                        ButtonOnly="false" Width="300" />
                    <ext:TreePanel ID="FolderTree" runat="server" Height="200" UseArrows="true" FieldLabel="Please select a directory"
                        AutoScroll="true" Animate="true" EnableDD="true" ContainerScroll="true" RootVisible="false">
                            <Root>
                                <ext:TreeNode Text="Composers" Expanded="true">
                                    <Nodes>
                                        <ext:TreeNode Text="Beethoven" Icon="UserGray" >
                                            <Nodes>
                                                <ext:TreeNode Text="Concertos">
                                                    <Nodes>
                                                        <ext:TreeNode Text="No. 1 - C" Icon="Music" />
                                                        <ext:TreeNode Text="No. 2 - B-Flat Major" Icon="Music" />
                                                        <ext:TreeNode Text="No. 3 - C Minor" Icon="Music" />
                                                        <ext:TreeNode Text="No. 4 - G Major" Icon="Music" />
                                                        <ext:TreeNode Text="No. 5 - E-Flat Major" Icon="Music" />
                                                    </Nodes>
                                                </ext:TreeNode>
                                                <ext:TreeNode Text="Quartets">
                                                    <Nodes>
                                                        <ext:TreeNode Text="Six String Quartets" Icon="Music" />
                                                        <ext:TreeNode Text="Three String Quartets" Icon="Music" />
                                                        <ext:TreeNode Text="Grosse Fugue for String Quartets" Icon="Music" />
                                                    </Nodes>
                                                </ext:TreeNode>
                                                <ext:TreeNode Text="Sonatas">
                                                    <Nodes>
                                                        <ext:TreeNode Text="Sonata in A Minor" Icon="Music" />
                                                        <ext:TreeNode Text="sonata in F Major" Icon="Music" />
                                                    </Nodes>
                                                </ext:TreeNode>
                                                <ext:TreeNode Text="Symphonies">
                                                    <Nodes>
                                                        <ext:TreeNode Text="No. 1 - C Major" Icon="Music" />
                                                        <ext:TreeNode Text="No. 2 - D Major" Icon="Music" />
                                                        <ext:TreeNode Text="No. 3 - E-Flat Major" Icon="Music" />
                                                        <ext:TreeNode Text="No. 4 - B-Flat Major" Icon="Music" />
                                                        <ext:TreeNode Text="No. 5 - C Minor" Icon="Music" />
                                                        <ext:TreeNode Text="No. 6 - F Major" Icon="Music" />
                                                        <ext:TreeNode Text="No. 7 - A Major" Icon="Music" />
                                                        <ext:TreeNode Text="No. 8 - F Major" Icon="Music" />
                                                        <ext:TreeNode Text="No. 9 - D Minor" Icon="Music" />
                                                    </Nodes>
                                                </ext:TreeNode>
                                            </Nodes>
                                        </ext:TreeNode>
                                        <ext:TreeNode Text="Brahms" Icon="UserGray">
                                            <Nodes>
                                                <ext:TreeNode Text="Concertos">
                                                    <Nodes>
                                                        <ext:TreeNode Text="Violin Concerto" Icon="Music" />
                                                        <ext:TreeNode Text="Double Concerto - A Minor" Icon="Music" />
                                                        <ext:TreeNode Text="Piano Concerto No. 1 - D Minor" Icon="Music" />
                                                        <ext:TreeNode Text="Piano Concerto No. 2 - B-Flat Major" Icon="Music" />
                                                    </Nodes>
                                                </ext:TreeNode>
                                                <ext:TreeNode Text="Quartets">
                                                    <Nodes>
                                                        <ext:TreeNode Text="Piano Quartet No. 1 - G Minor" Icon="Music" />
                                                        <ext:TreeNode Text="Piano Quartet No. 2 - A Major" Icon="Music" />
                                                        <ext:TreeNode Text="Piano Quartet No. 3 - C Minor" Icon="Music" />
                                                        <ext:TreeNode Text="Piano Quartet No. 3 - B-Flat Minor" Icon="Music" />
                                                    </Nodes>
                                                </ext:TreeNode>
                                                <ext:TreeNode Text="Sonatas">
                                                    <Nodes>
                                                        <ext:TreeNode Text="Two Sonatas for Clarinet - F Minor" Icon="Music" />
                                                        <ext:TreeNode Text="Two Sonatas for Clarinet - E-Flat Major" Icon="Music" />
                                                    </Nodes>
                                                </ext:TreeNode>
                                                <ext:TreeNode Text="Symphonies">
                                                    <Nodes>
                                                        <ext:TreeNode Text="No. 1 - C Minor" Icon="Music" />
                                                        <ext:TreeNode Text="No. 2 - D Minor" Icon="Music" />
                                                        <ext:TreeNode Text="No. 3 - F Major" Icon="Music" />
                                                        <ext:TreeNode Text="No. 4 - E Minor" Icon="Music" />
                                                    </Nodes>
                                                </ext:TreeNode>
                                            </Nodes>
                                        </ext:TreeNode>
                                        <ext:TreeNode Text="Mozart" Icon="UserGray">
                                            <Nodes>
                                                <ext:TreeNode Text="Concertos">
                                                    <Nodes>
                                                        <ext:TreeNode Text="Piano Concerto No. 12" Icon="Music"  />
                                                        <ext:TreeNode Text="Piano Concerto No. 17" Icon="Music"  />
                                                        <ext:TreeNode Text="Clarinet Concerto" Icon="Music"  />
                                                        <ext:TreeNode Text="Violin Concerto No. 5" Icon="Music"  />
                                                        <ext:TreeNode Text="Violin Concerto No. 4" Icon="Music"  />
                                                    </Nodes>
                                                </ext:TreeNode>
                                            </Nodes>
                                        </ext:TreeNode>
                                    </Nodes>
                                </ext:TreeNode>
                            </Root>
                    </ext:TreePanel>
                </Items>
                <Buttons>
                    <ext:Button ID="Button1" runat="server" Text="Upload" />
                </Buttons>
            </ext:Panel>
        </Items>
    </ext:Window>
</form>

答案 1 :(得分:1)

什么是

treeNode.Listeners.Click.Handler = string.Format(new CultureInfo("en-US"), "#{{MainPanel}}.load('{0}');#{{MainPanel}}.setIconClass('{1}');#{{MainPanel}}.setTitle('{2}');", siteMapNode.Url, iconCls, siteMapNode.Title);

在做什么?

请删除该行,因为没有名称为&#34; MainPanel&#34;并查看它是否已解决。