【问题标题】:How to set textbox text by AspxTreelist's focused node如何通过 AspxTreelist 的焦点节点设置文本框文本
【发布时间】:2017-06-22 11:25:49
【问题描述】:

我有一个 Treelist,我从一个值列表中填充它。我还获得了选定的节点值。但是,当我想按该值设置此文本框时,我失败了。文本框中没有任何内容。如何用这个 selectednode 值填充文本框?

<dx:ASPxTreeList ID="ASPxTreeList1" runat="server" EnableTheming="True" Theme="Moderno" AutoGenerateColumns="True" KeyFieldName="ID" ParentFieldName="ReportsTo" Width="280px" 
                     ClientInstanceName="treeList" OnCustomDataCallback="treeList_CustomDataCallback" >
        <Columns>
            <dx:TreeListTextColumn FieldName="ProjectName" VisibleIndex="0">
            </dx:TreeListTextColumn>
            <dx:TreeListTextColumn FieldName="ReportsTo" VisibleIndex="3" Visible="False">
            </dx:TreeListTextColumn>
        </Columns>
        <Settings GridLines="Horizontal" ScrollableHeight="300" SuppressOuterGridLines="true" VerticalScrollBarMode="Visible" />
        <Settings ShowColumnHeaders="False" ShowTreeLines="False" />
        <SettingsBehavior AllowFocusedNode="True" />
        <ClientSideEvents CustomDataCallback="function(s, e) { document.getElementById('messageText').innerHTML = e.result; }"
                          FocusedNodeChanged="function(s, e) {
        var key = treeList.GetFocusedNodeKey();
        treeList.PerformCustomDataCallback(key);
    }" />

    </dx:ASPxTreeList>
        <dx:ASPxTextBox ID="txtSelectedNode" runat="server" Theme="Moderno" Width="170px">
    </dx:ASPxTextBox>
        <SettingsPager Mode="ShowAllNodes">
        </SettingsPager>
        <SettingsDataSecurity AllowDelete="False" AllowEdit="False" AllowInsert="False" />
    </dx:ASPxTreeList>


 protected void treeList_CustomDataCallback(object sender, TreeListCustomDataCallbackEventArgs e)
    {
        string key = e.Argument.ToString();
        TreeListNode node = ASPxTreeList1.FindNodeByKeyValue(key);
        if (!node.HasChildren)
        {             
            txtSelectedNode.Text = node.GetValue("ProjectName").ToString();
         }
    }

【问题讨论】:

    标签: c# asp.net webforms devexpress treelist


    【解决方案1】:

    我有一个解决方案。需要使用 OnCustomJSProperties 属性。我像这样更新了我的代码块:

    <dx:ASPxTreeList ID="ASPxTreeList1" runat="server" EnableTheming="True" Theme="Moderno" AutoGenerateColumns="True" KeyFieldName="ID" ParentFieldName="ReportsTo" Width="280px"
            ClientInstanceName="treeList" OnCustomJSProperties="TreeList_CustomJSProperties">
            <Columns>
                <dx:TreeListTextColumn FieldName="ProjectName" VisibleIndex="0">
                </dx:TreeListTextColumn>
                <dx:TreeListTextColumn FieldName="ReportsTo" VisibleIndex="3" Visible="False">
                </dx:TreeListTextColumn>
            </Columns>
            <Settings GridLines="Horizontal" ScrollableHeight="300" SuppressOuterGridLines="true" VerticalScrollBarMode="Visible" />
            <Settings ShowColumnHeaders="False" ShowTreeLines="False" />
            <SettingsBehavior AllowFocusedNode="True" />
            <ClientSideEvents FocusedNodeChanged="function(s, e) {
                var key = treeList.GetFocusedNodeKey();
                var value = treeList.cpNodes[key];
                txtNode.SetText(value);
        }" />
            <SettingsPager Mode="ShowAllNodes">
            </SettingsPager>
            <SettingsDataSecurity AllowDelete="False" AllowEdit="False" AllowInsert="False" />
        </dx:ASPxTreeList>
        <dx:ASPxTextBox ID="txtSelectedNode" ClientInstanceName="txtNode" runat="server" Theme="Moderno" Width="170px">
        </dx:ASPxTextBox>
    
    
    protected void TreeList_CustomJSProperties(object sender, TreeListCustomJSPropertiesEventArgs e)
        {
            ASPxTreeList treeList = sender as ASPxTreeList;
            Hashtable nameTable = new Hashtable();
            foreach (TreeListNode node in treeList.GetAllNodes())
                if (!node.HasChildren)
                {
                    nameTable.Add(node.Key, string.Format("{0}", node["ProjectName"]));
                    e.Properties["cpNodes"] = nameTable;
                }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-10
      • 1970-01-01
      • 2014-04-24
      相关资源
      最近更新 更多