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

Disable edit on Details table from Code Behind

2 Answers 90 Views
Grid
This is a migrated thread and some comments may be shown as answers.
AkAlan
Top achievements
Rank 2
AkAlan asked on 27 Sep 2011, 02:41 AM
I have a radgrid using master detail hierarchy and I want to be able to disable the edit and insert commands depending on the user. Where is the best place/event to disable these commands? I am able to prevent the Insert command from being visible but can't find where to hide the Edit.
Protected Sub RadGrid1_ItemCreated(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated
        If (TypeOf e.Item Is GridCommandItem) Then
            Dim commandItem As GridCommandItem = CType(e.Item, GridCommandItem)
            commandItem.Visible = False
        End If
    End Sub

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 27 Sep 2011, 06:00 AM
Hi AkAlan,

You can go use the following code to disable edit on detail table.

VB:
Protected Sub radgrid1_ItemDataBound(sender As Object, e As GridItemEventArgs)
    If e.Item.OwnerTableView.Name = "Orders" Then
      If TypeOf e.Item Is GridDataItem Then
        Dim gridItem As GridDataItem = TryCast(e.Item, GridDataItem)
        Dim s As [String] = gridItem("OrderID").Text
        If s = "10643" Then
          DirectCast(gridItem("edit").Controls(0), LinkButton).Enabled = False
        End If
      End If
    End If
End Sub


Thanks,
Princy.
0
AkAlan
Top achievements
Rank 2
answered on 27 Sep 2011, 06:02 PM

Thanks, got it to work using your help. I posted what worked for me since I was using an image button with a different name.

Protected Sub radgrid1_ItemDataBound(sender As Object, e As GridItemEventArgs) Handles RadGrid1.ItemDataBound
 
       If e.Item.OwnerTableView.Name = "Drawings" Then
           If TypeOf e.Item Is GridDataItem Then
               Dim gridItem As GridDataItem = TryCast(e.Item, GridDataItem)
               Dim editImage As ImageButton = DirectCast(gridItem("EditCommandColumn1").Controls(0), ImageButton)
               If User.IsInRole("MyRole") = True  Then
                    editImage.Visible = True
               Else
                   editImage.Visible = False
               End If
 
 
           End If
       End If
   End Sub


Tags
Grid
Asked by
AkAlan
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
AkAlan
Top achievements
Rank 2
Share this question
or