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

Hide GridEditCommandColumn for specific rows.

4 Answers 109 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 22 Sep 2011, 01:49 PM
I have some items in a database that are system items and I don't want users to be able to change them. Is there a way I can hide the GridEditCommandColumn and GridButtonColumn (delete) for specific rows only? e.g. I have 4 rows with a DayKeyName, ID, it's an identity field and I want to hide 1 and 2 but not 3 and 4.

I tried this but I think I'm missing something:
Protected Sub RadGrid_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid.ItemDataBound
        Dim Datakey As Integer = Nothing
 
        If TypeOf e.Item Is GridDataItem Then
            Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
            Datakey = item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("ID")
        End If
 
        Dim tableView As GridTableView = DirectCast(e.Item.OwnerTableView, GridTableView)
        Dim editColumndetail As GridEditCommandColumn = DirectCast(tableView.GetColumn("EditColumn"), GridEditCommandColumn)
 
        If Datakey = 1 Or Datakey = 2 Then
            editColumndetail.Visible = False
        Else
            editColumndetail.Visible = True
        End If
 
    End Sub

Thanks for you help!!

4 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 22 Sep 2011, 02:03 PM
Hello,

in below code i can do this by two way
1. using css
2. remove control from editcolumn

protected void ModifiedContentsReportGrid_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = e.Item as GridDataItem;
            string strName = item.GetDataKeyValue("Name").ToString();
            if (strName == "1")
            {
                item["EditColumn"].CssClass = "RemoveEdit";
 
                // or
 
                LinkButton lnk = item["EditColumn"].Controls[0] as LinkButton;
                item["EditColumn"].Controls.Remove(lnk);
            }
                        
        }
    }
<style type="text/css">
       .RemoveEdit
       {
           display:none !important;
       }
   </style>
<MasterTableView  DataKeyNames="Name">
<telerik:GridEditCommandColumn UniqueName="EditColumn"></telerik:GridEditCommandColumn>


Thanks,
Jayesh Goyani
0
Chris
Top achievements
Rank 1
answered on 23 Sep 2011, 01:12 PM
Thanks Jayesh! That worked like a charm!

Now I just need to suppress the edit action on double click for those items. I tried this but it seems the datakeys that get returned are null.

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
        function RowDblClick(sender, eventArgs) {
            If (eventArgs.getDataKeyValue("ID") > 2){                  
            sender.get_masterTableView().editItem(eventArgs.get_itemIndexHierarchical());                   
            }
        }               
    </script>
</telerik:RadCodeBlock
<ClientSettings>
         <ClientEvents OnRowDblClick="RowDblClick" />
</ClientSettings>

Thanks again for your help!
0
Accepted
Shinu
Top achievements
Rank 1
answered on 26 Sep 2011, 06:07 AM
Hello Chris,

Please make sure that you have set the ClientDataKeyNames.
aspx:
<MasterTableView CommandItemDisplay="Top" ClientDataKeyNames="ID">
Thanks,
Shinu.
0
Chris
Top achievements
Rank 1
answered on 30 Sep 2011, 05:07 PM
Thanks Shinu! That's what I was missing.
Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Chris
Top achievements
Rank 1
Shinu
Top achievements
Rank 1
Share this question
or