如何从RadTreeList UpdateCommand中找到DataKeyValue?

时间:2011-05-18 00:24:51

标签: asp.net telerik rad-controls radtreelist

我在进行更新时如何找到DataKey?我已经尝试了一切......

Private Sub rtlAccounts_UpdateCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.TreeListCommandEventArgs) Handles rtlAccounts.UpdateCommand
    Dim txtAccountDescription As RadTextBox = TryCast(e.Item.FindControl("txtAccountDescription"), RadTextBox)
    Dim txtAdminName As RadTextBox = TryCast(e.Item.FindControl("txtAdminName"), RadTextBox)
    Dim txtAdminEmail As RadTextBox = TryCast(e.Item.FindControl("txtAdminEmail"), RadTextBox)
    Dim rcbStatus As RadComboBox = TryCast(e.Item.FindControl("rcbStatus"), RadComboBox)
    Dim rntDocRetention As RadNumericTextBox = TryCast(e.Item.FindControl("rntDocRetention"), RadNumericTextBox)

    Dim item As TreeListEditableItem = TryCast(e.Item, TreeListEditableItem)
    Dim MyDataKeyID As String =  'Now what???
End Sub

还想知道如何从InsertCommand和UpdateCommand中找到ParentDataKeyValue。

1 个答案:

答案 0 :(得分:1)

要获取DataKeyValue和ParentDataKeyValue,请将最后两行更改为以下内容:

Dim editedItem As TreeListEditFormItem = CType(e.Item, TreeListEditFormItem)
Dim dataKeyValue As String = _
    editedItem.ParentItem.GetDataKeyValue("EmployeeID").ToString()
Dim parentDataKeyValue As String = _
    editedItem.ParentItem.GetParentDataKeyValue("ReportsTo").ToString()

Telerik's documentation,如果您使用 InPlace 编辑模式,则应将TreeListEditableItem转换为TreeListDataItem;如果您使用 EditForms ,则应将TreeListEditableItem转换为TreeListEditFormItem

为了让GetDataKeyValue和GetParentDataKeyValue返回您想要的值,您必须在定义RadTreeList时将它们设置在相应的DataKeyNames和ParentDataKeyNames值中:

<telerik:RadTreeList ID="EmployeeTreeList" runat="server" 
    DataKeyNames="EmployeeID" 
    ParentDataKeyNames="ReportsTo">
    <Columns>
        <%-- Add column definitions here --%>
    </Columns>
</telerik:RadTreeList>