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

Disable Insert and Delete on RadGrid

10 Answers 568 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 1
Bob asked on 22 Apr 2008, 12:46 AM
I am trying to setup a grid that only allow Update all others are disabled.  I set 

AllowAutomaticInserts

to false and I can still insert a new row.  How can I disable these features?

10 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 22 Apr 2008, 10:56 AM
Hello Bob,

I have attached small example to illustrate you how to achieve this.

Kind regards,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Bob
Top achievements
Rank 1
answered on 22 Apr 2008, 05:00 PM
I looked at your code and the only difference was you set the property to TRUE.  I tried that and still in the left hand corner I still have the icon to insert a new row.  When I click on it it tries to insert a row but when save because my data source does not have an insert command I get an error.  I do not want for this page any user trying to insert a row...only update existiung rows.

I want to attach a pix of the grid so you understand what I am talking about...but I see no easy way.  Anyway I hope you can understand my data source only has an Udate command no Ddelete or Insert but still I see the icon at the top of the grid that allows insert.

0
Iana Tsolova
Telerik team
answered on 23 Apr 2008, 11:13 AM
Hi Bob,

You need to set the RadGrid MasterTableView CommandItemDisplay property to None if you don't want the insert button on the top left to be visible. Give this suggestion a try and let us know if the problem persists. 
 
All the best,
Iana
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Bob
Top achievements
Rank 1
answered on 23 Apr 2008, 11:39 AM
Yes that solved the problem.  I was hoping I could retain the refresh and not the the Insert.

Thanks.
0
Shinu
Top achievements
Rank 1
answered on 23 Apr 2008, 12:37 PM
Hi Bob,

You can try the following code snippet to hide the AddNewRecord button.

CS:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
 
        if (e.Item is GridCommandItem) 
        { 
            GridCommandItem cmditm = (GridCommandItem)e.Item; 
            LinkButton lnkbtn1 = (LinkButton)cmditm.FindControl("InitInsertButton"); 
            lnkbtn1.Visible = false
          
        } 
   } 


Hope this helps..
Shinu.
0
bill
Top achievements
Rank 1
answered on 11 Jul 2008, 06:44 PM
This removed the text part of the button but the image is still there and can be clicked.
0
Princy
Top achievements
Rank 1
answered on 14 Jul 2008, 06:00 AM
Hello Bill,

You can try out the following code to remove/hide the CommandItem image as well as text.

CS:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridCommandItem) 
        { 
            GridCommandItem cmditm = (GridCommandItem)e.Item; 
            Button btn1 = (Button)cmditm.FindControl("AddNewRecordButton"); 
            btn1.Visible = false
            LinkButton lnkbtn1 = (LinkButton)cmditm.FindControl("InitInsertButton"); 
            lnkbtn1.Visible = false;  
        }  
    } 

Regards
Princy.


0
Rybovich IT Department
Top achievements
Rank 1
answered on 14 Jan 2009, 08:48 PM
Could you convert this code to VB for me?  We took a stab at it but couldn't get it.
0
Princy
Top achievements
Rank 1
answered on 15 Jan 2009, 04:13 AM
Hello John,

Below given is the VB code to hide the AddNewRecord button and image from the command item:
VB:
     Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) 
         If TypeOf e.Item Is GridCommandItem Then 
             Dim cmditm As GridCommandItem = DirectCast(e.Item, GridCommandItem) 
             Dim btn1 As Button = DirectCast(cmditm.FindControl("AddNewRecordButton"), Button) 
             btn1.Visible = False 
             Dim lnkbtn1 As LinkButton = DirectCast(cmditm.FindControl("InitInsertButton"), LinkButton) 
             lnkbtn1.Visible = False 
         End If 
     End Sub 

You can also use the following Conversion Tool to convert from C# to VB and vice versa.
Convert C# to VB.NET

Thanks
Princy.
0
Rybovich IT Department
Top achievements
Rank 1
answered on 15 Jan 2009, 01:21 PM
Princy,
That worked.  Thanks for the help!
Tags
Grid
Asked by
Bob
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Bob
Top achievements
Rank 1
Iana Tsolova
Telerik team
Shinu
Top achievements
Rank 1
bill
Top achievements
Rank 1
Princy
Top achievements
Rank 1
Rybovich IT Department
Top achievements
Rank 1
Share this question
or