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

[Solved] Command Item Get Key ID

1 Answer 192 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Smally
Top achievements
Rank 1
Smally asked on 09 Sep 2009, 10:02 PM
I have a 2 level hiearchy grid. The detail table has a commanditemtemplate with a link inside for add item. I am needing to add an onclick javascript event to this in the code behind and get the datakeyvalue of the master table row that we are adding to. So for instance
MasterTable = Schedule
DetailTable =  Event
Key = ScheduleID

When i databind the event datasource i want to use the event to grab the ScheduleID from the mastertable row and add it to a javascript call ShowEditForm(ScheduleId)

How can I get the key in the commanddataitem?
I am already grabbing the link and inserting a fake call that works - but I need that darn key? Any thoughts how i can get it here? I know how to get it if i'm in a griddataitem but not here?

 

If TypeOf (e.Item) Is GridCommandItem And e.Item.OwnerTableView.DataSourceID = "SqlDates" Then

 

 

Dim dataitem As GridCommandItem = CType(e.Item, GridCommandItem)

 

 

 

Dim hypr As HyperLink = CType(dataitem.FindControl("AddLink"), System.Web.UI.WebControls.HyperLink)

 

hypr.Attributes(

"onclick") = [String].Format("return ShowEditForm('{0}'", 0)

 

 

 

'editLink.Attributes("onclick") = [String].Format("return ShowEditForm('{0}','{1}');", dataitem("MessageId").Text, e.Item.ItemIndex)

 

 

End If

 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 Sep 2009, 05:16 AM
Hi,

Try the following code snippet to access the key ID from the Parent row.

VB:
 
 If (TypeOf e.Item Is GridCommandItem) AndAlso (e.Item.OwnerTableView.DataSourceID = "SqlDates"Then 
     Dim parentItem As GridDataItem = DirectCast(e.Item.OwnerTableView.ParentItem, GridDataItem) 
         
     Dim strKey As String = parentItem.GetDataKeyValue("ScheduleID").ToString() 
 End If 


Thanks
Princy
Tags
Grid
Asked by
Smally
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or