Disable edit on Details table from Code Behind

3 posts, 0 answers
  1. AkAlan
    AkAlan avatar
    121 posts
    Member since:
    Jun 2009

    Posted 26 Sep 2011 Link to this post

    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. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 27 Sep 2011 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. AkAlan
    AkAlan avatar
    121 posts
    Member since:
    Jun 2009

    Posted 27 Sep 2011 Link to this post

    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


Back to Top