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

Hide/show new record, edit and delete buttons

1 Answer 157 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 27 Feb 2011, 04:28 PM
Hi,
I have a RadGrid that is bound to a SqlDataSource. I want to show or hide the new record button in the CommandItem area as well as the edit and delete buttons based on a value from the SqlDataSource.
Ive been looking at this for a bit and it does not seem like there is a simple way to do it.
Any help would be greatly appreciated.
Thanks
Alex

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 28 Feb 2011, 07:56 AM
Hello Alex,

You can show/hide 'AddNewRecord' button by setting the following code snippet to true/false.
C#:
RadGrid1.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = true;

I am not sure how do you set Edit and Delete in RadDrid. The following code snippet shows hiding edit/delete button(uses GridButtonColumn).

ASPX:
<telerik:GridButtonColumn CommandName="Edit" ButtonType="LinkButton" UniqueName="editBtn"
    Text="Edit">
</telerik:GridButtonColumn>
<telerik:GridButtonColumn CommandName="Delete" ButtonType="LinkButton" UniqueName="deleteBtn"
    Text="Delete">
</telerik:GridButtonColumn>

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridDataItem)
       {
           GridDataItem item = e.Item as GridDataItem;
           if ( //your condition)
           {
               LinkButton editBtn = (LinkButton)item["editBtn"].Controls[0];
               editBtn.Visible = false;
               LinkButton deleteBtn = (LinkButton)item["deleteBtn"].Controls[0];
               deleteBtn.Visible = false;
           }
       }
  }

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