【问题标题】:Telerik RadTreeList: GetDataKeyValues returns nullTelerik RadTreeList:GetDataKeyValues 返回 null
【发布时间】:2012-03-05 15:38:37
【问题描述】:

我试图在我的 rad 树列表中获取客户端数据键值,但它总是返回 null:

private List<xItems> GetTreeListChanges()
{
    List<xItems> xItems = new List<xItems>();
    foreach(TreeListDataItem rtlItem in rtlxItems.Items)
    {
        string xItemsId = Convert.ToString(rtlItem.GetDataKeyValue("xItemsId"));
    }
    [...]
}

这是标记代码,其中我的数据键定义明确:

<telerik:RadTreeList ID="rtlxItems" runat="server" AllowMultiItemEdit="false"
        ParentDataKeyNames="ParentId" DataKeyNames="ChlidId" ClientDataKeyNames="xItemsId">

【问题讨论】:

    标签: c# asp.net asp.net-ajax telerik


    【解决方案1】:

    XItemsId 只是一个客户端数据键,您应该更改 getDataKey 以使用 ChildId(您在 dataKeyNames 声明中也有错字

    private List<xItems> GetTreeListChanges()
    {
        List<xItems> xItems = new List<xItems>();
        foreach(TreeListDataItem rtlItem in rtlxItems.Items)
        {
            string xItemsId = Convert.ToString(rtlItem.GetDataKeyValue("ChildId"));
        }
        [...]
    } 
    
    <telerik:RadTreeList ID="rtlxItems" runat="server" AllowMultiItemEdit="false"
            ParentDataKeyNames="ParentId" DataKeyNames="ChildId" ClientDataKeyNames="xItemsId">
    

    【讨论】:

    • 我得到以下异常:KeyNames collection length must match ParentKeyNames collection length.
    • 从一开始,当我在 ParentDataKeyNamesDataKeyNames 属性中各有一个以上的键时,我总是遇到此错误。
    • 我还没有看到允许为树列表指定多个 dataKeyName 的文档,其他控件允许使用逗号分隔的列表。您的 parentId 和 xItemsId 或 Child ID 需要具有相同的字段类型,仅此而已。因此,要么使用 xItemsId 作为该项目的数据键名,要么使用 childID 并将此代码更改为使用 childId:rtlItem.GetDataKeyValue("childID")
    猜你喜欢
    • 2022-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-10
    • 1970-01-01
    • 1970-01-01
    • 2020-06-28
    • 1970-01-01
    相关资源
    最近更新 更多