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

Prevent delete for 1 row

1 Answer 77 Views
Grid
This is a migrated thread and some comments may be shown as answers.
SK
Top achievements
Rank 1
SK asked on 22 Oct 2010, 09:37 PM
I'm using a radgrid with a gridbuttoncolumn as the last column in the grid. It has a delete command. 

How would I prevent the button from appearing for a single row? The data is sorted by PK "id" field. It's the first item in the grid (id=1) that I do not want anyone to delete. Is there any way to hide the delete button for this particular row? Thanks.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 25 Oct 2010, 05:48 AM
Hello,
You can try the following code snippet to achieve your requirement.

Mark-Up:
<Columns>
           <telerik:GridBoundColumn DataField="EmployeeID" HeaderText="EmployeeID" UniqueName="EmployeeID">
           </telerik:GridBoundColumn>
           <telerik:GridButtonColumn CommandName="Delete" HeaderText="Delete" UniqueName="Delete"  Text="Delete">
           </telerik:GridButtonColumn>
 </Columns>

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
  {
      if (e.Item is GridDataItem)
      {
          GridDataItem item = (GridDataItem)e.Item;
          if (item["id"].Text == "1")
          {
              LinkButton btn = (LinkButton)item["Delete"].Controls[0];//accessing delete button using column unique name
              btn.Visible = false;
          }
      }
  }

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