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

Get data key in ItemDataboundEvent

3 Answers 102 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 05 Apr 2012, 08:43 PM
I have seen examples when to get datakey when you are using such
if typeof e.item is gridedititem and also e.item.isineditmode then

but I am only using the following in my itemdatabound to change add a datakey to a hyperlink)

If TypeOf e.Item Is GridDataItem Then
           Dim NonCrit As HyperLink = CType(e.Item.FindControl("hyNonCrit"), HyperLink)
           Dim HyCrit As HyperLink = CType(e.Item.FindControl("hyCrit"), HyperLink)
           Dim key As Integer = myRadGrid.SelectedItems(0).OwnerTableView.DataKeyValues("intPositionId")
           If CInt(HyCrit.Text) > 0 Then
               HyCrit.NavigateUrl = "TaskManage.aspx?Crit=" & key
               e.Item.Cells(13).BackColor = Drawing.Color.Tomato
               HyCrit.ForeColor = Drawing.Color.Tomato
           End If
           If CInt(NonCrit.Text) > 0 Then
               NonCrit.NavigateUrl = "TaskManage.aspx?NCrit=" & key
           End If
       End If

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 06 Apr 2012, 06:42 AM
Hello Kevin,

if (e.Item is GridEditableItem && e.Item.IsInEditMode)
       {
           GridEditableItem item = e.Item as GridEditableItem;
           string strKey = item.GetDataKeyValue("ID").ToString();
        
       }


Thanks,
Jayesh Goyani
0
Kevin
Top achievements
Rank 1
answered on 06 Apr 2012, 02:13 PM
Hi jayesh,

I cannot use that mode.  If I do it cuts out my hyperlinks becuase its not in edit mode.  it is just a griddataitem.  When I putthis code under edititem it cuts out the links and the coloring of the grid.  There has to be a way to get a hold of the datakey in griddataitem.
0
Kevin
Top achievements
Rank 1
answered on 06 Apr 2012, 02:27 PM
HI,

i found another one of theads and tried it and got the datakey value
.
 If TypeOf e.Item Is GridDataItem Then
            Dim NonCrit As HyperLink = CType(e.Item.FindControl("hyNonCrit"), HyperLink)
            Dim HyCrit As HyperLink = CType(e.Item.FindControl("hyCrit"), HyperLink)
            Dim Item As GridDataItem = DirectCast(e.Item, GridDataItem)
            Dim Key As Integer = Item.GetDataKeyValue("intPositionId")
            Dim cell As TableCell = Item("Person")
Tags
Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Kevin
Top achievements
Rank 1
Share this question
or