Find DataKey in UpdateCommand?

6 posts, 0 answers
  1. Rich Coleman
    Rich Coleman avatar
    19 posts
    Member since:
    Jan 2008

    Posted 17 May 2011 Link to this post

    How on earth do I find the DataKey when I'm doing an update?  I've tried everything...


    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

    Also would like to know how to find the ParentDataKey from an InsertCommand and the UpdateCommand as well.
  2. Tsvetina
    Admin
    Tsvetina avatar
    1873 posts

    Posted 18 May 2011 Link to this post

    Hi Rich,

    Take a look at the following two articles showing how to access values including (datakey value) when updating records. You can also find in the same documentation category articles concerning the insert handling as well.

    http://www.telerik.com/help/aspnet-ajax/treelist-updating-inplace-editforms.html
    http://www.telerik.com/help/aspnet-ajax/treelist-updating-formtemplate-usercontrol.html

    All the best,
    Tsvetina
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rich Coleman
    Rich Coleman avatar
    19 posts
    Member since:
    Jan 2008

    Posted 18 May 2011 Link to this post

    Ahh - I saw another example using TreeListEditableItem so I got mentally locked into using that as the e.Item type.  Ok, so that works perfect now.

    Ok, so it doesn't work for the DeleteCommand, however.  How do I get the DataKeyValue for that?

    Private Sub rtlAccounts_DeleteCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.TreeListCommandEventArgs) Handles rtlAccounts.DeleteCommand
        Dim item As TreeListEditFormItem = TryCast(e.Item, TreeListEditFormItem)
        Dim ID As Integer = item.ParentItem.GetDataKeyValue("ID"'<--- Object reference not set to an instance of an object on this line
        Call Dashboard.Account.Delete(ID)
        rtlAccounts.Rebind()
    End Sub
  5. Rich Coleman
    Rich Coleman avatar
    19 posts
    Member since:
    Jan 2008

    Posted 18 May 2011 Link to this post

    Ah - never mind.  Apparently the e.item is a TreeListDataItem in the DeleteCommand context so I can just access it directly now:

    Dim item As TreeListDataItem = TryCast(e.Item, TreeListDataItem)
    Dim ID As Integer = item.GetDataKeyValue("ID")

    Thanks for you help!!
  6. Rich Coleman
    Rich Coleman avatar
    19 posts
    Member since:
    Jan 2008

    Posted 18 May 2011 Link to this post

    Weird that that same method doesn't work for InsertCommand from what I can tell though.  I have to do this to get the ParentID...

    Dim table As New Hashtable()
    Dim item As TreeListEditableItem = TryCast(e.Item, TreeListEditableItem)
    item.ExtractValues(table)
    Dim ID as Integer = table("ParentID")


    Is there a less convoluted way to get it if I just want the ParentID for an insert?
  7. Tsvetina
    Admin
    Tsvetina avatar
    1873 posts

    Posted 24 May 2011 Link to this post

    Hi Rich,

    Since the ParentID is resolved at the time the insert happens, there is no other way to access it at this point.

    The more straightforward way (using the GetParentDataKeyValue()) is available once you get hold of the newly inserted TreeListDataItem but this will be available later in the ItemDataBound and PreRender events of the treelist. However, in both events  you would need to check the DataKeyValue in order to recognize the new item.

    Greetings,
    Tsvetina
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017