This is a migrated thread and some comments may be shown as answers.

Find DataKey in UpdateCommand?

5 Answers 239 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Rich Coleman
Top achievements
Rank 1
Rich Coleman asked on 18 May 2011, 12:51 AM
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.

5 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 18 May 2011, 06:50 AM
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.

0
Rich Coleman
Top achievements
Rank 1
answered on 18 May 2011, 02:31 PM
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
0
Rich Coleman
Top achievements
Rank 1
answered on 18 May 2011, 02:35 PM
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!!
0
Rich Coleman
Top achievements
Rank 1
answered on 18 May 2011, 03:12 PM
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?
0
Tsvetina
Telerik team
answered on 24 May 2011, 08:22 AM
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.

Tags
TreeList
Asked by
Rich Coleman
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Rich Coleman
Top achievements
Rank 1
Share this question
or