Disable Insert and Delete on RadGrid

11 posts, 0 answers
  1. Bob
    Bob avatar
    21 posts
    Member since:
    Mar 2008

    Posted 21 Apr 2008 Link to this post

    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?

  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 22 Apr 2008 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Bob
    Bob avatar
    21 posts
    Member since:
    Mar 2008

    Posted 22 Apr 2008 Link to this post

    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.

  5. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 23 Apr 2008 Link to this post

    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
  6. Bob
    Bob avatar
    21 posts
    Member since:
    Mar 2008

    Posted 23 Apr 2008 Link to this post

    Yes that solved the problem.  I was hoping I could retain the refresh and not the the Insert.

    Thanks.
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 23 Apr 2008 Link to this post

    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.
  8. bill
    bill avatar
    7 posts
    Member since:
    Nov 2007

    Posted 11 Jul 2008 Link to this post

    This removed the text part of the button but the image is still there and can be clicked.
  9. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 14 Jul 2008 Link to this post

    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.


  10. Rybovich IT Department
    Rybovich IT Department avatar
    3 posts
    Member since:
    Apr 2008

    Posted 14 Jan 2009 Link to this post

    Could you convert this code to VB for me?  We took a stab at it but couldn't get it.
  11. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 14 Jan 2009 Link to this post

    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.
  12. Rybovich IT Department
    Rybovich IT Department avatar
    3 posts
    Member since:
    Apr 2008

    Posted 15 Jan 2009 Link to this post

    Princy,
    That worked.  Thanks for the help!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017