This is a migrated thread and some comments may be shown as answers.
RadGrid: add new record and edit record
13 Answers 509 Views
This is a migrated thread and some comments may be shown as answers.
Shehab
Top achievements
Rank 1
Shehab asked on 05 Aug 2008, 02:28 PM
Hi All,

How do I disable grid editing if I am adding a new record and how do I disable adding a new record if I am editing in the grid? only one function at a time until you click on Insert, Update, or cancle button.

Thank you in Advance,
Shehab

13 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 06 Aug 2008, 06:44 AM
Hello Shehab,

One suggestion for your case would be to disable the InsertButton when in EditMode and disable the EditButtons when in InsertMode. Try out the code below for the same.

cs:
  protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
      if (e.Item.IsInEditMode) 
          { 
           foreach (GridCommandItem cmditm in RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)) 
            {               
                Button btn1 = (Button)cmditm.FindControl("AddNewRecordButton"); 
                btn1.Enabled = false
                //To disable the LinkButton 
                LinkButton lnkbtn1 = (LinkButton)cmditm.FindControl("InitInsertButton"); 
                lnkbtn1.Enabled = false;  
            } 
             
          } 
 
     if (e.Item.OwnerTableView.IsItemInserted) 
         { 
           foreach (GridDataItem dat in RadGrid1.MasterTableView.Items) 
             { 
                   LinkButton edit = (LinkButton)dat["EditCol"].Controls[0]; 
                   edit.Enabled = false
             } 
           } 
    } 

Thanks
Princy.

0
Stewart Ellis
Top achievements
Rank 1
answered on 08 Aug 2008, 08:50 PM
Princy I have some questions with your code example...

1. From what I can tell, the grid is editMode (e.Item.IsInEditMode) regardless of whether its editing of an existing row or adding a new one. When I implemented your example, my insert button was not enabled, regardless of whether I clicked insert or edit.

2. Regarding your 2nd code block, how does that work with when I don't have an editcolumn but instead I'm using FormTemplate?


thanks,
Stewart
0
Cres
Top achievements
Rank 1
answered on 10 Aug 2008, 03:20 PM
hi shehab,

if your UI could be a toolbar or buttons under the command item template, then you could control all of these accordingly via the radgrid's current mode flags. lots of examples on the live demo.

hth,
-cris
0
Princy
Top achievements
Rank 1
answered on 11 Aug 2008, 06:40 AM
Hello Stewart,

1.If you want to enable the AddNewRecord button in the Insert mode and disable it in the Edit mode, you can try out the following code.
cs:
 protected void RadGrid4_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if ((e.Item.IsInEditMode) && (!e.Item.OwnerTableView.IsItemInserted)) 
          { 
            foreach (GridCommandItem cmditm in RadGrid4.MasterTableView.GetItems(GridItemType.CommandItem)) 
            {               
                Button btn1 = (Button)cmditm.FindControl("AddNewRecordButton"); 
                btn1.Enabled = false;                 
                LinkButton lnkbtn1 = (LinkButton)cmditm.FindControl("InitInsertButton"); 
                lnkbtn1.Enabled = false;  
             }             
          } 
 
           if (e.Item.OwnerTableView.IsItemInserted) 
           { 
               foreach (GridDataItem dat in RadGrid4.MasterTableView.Items) 
               { 
                   LinkButton edit = (LinkButton)dat["Edit"].Controls[0]; 
                   edit.Enabled = false
               } 
           } 
   } 

2.The provided code should work if you have an EditCommandColumn only.


0
Shehab
Top achievements
Rank 1
answered on 18 Aug 2008, 06:53 PM
Hi Princy,

Thanks for all the help. I still have a problem with this code; it works fine when I am adding a new row in the Insert Button click because I define the edit button and disable it like this:
Dim edit As LinkButton = DirectCast(dat("EditCommandColumn1").Controls(0), LinkButton)  
                edit.Enabled = False 
However; when I am in edit mode it will error out Object not set to an instant of an object, I think because it can't find the control to assign it to a button and disable it and I honestly not sure what the name of the controler should be changed to here is the line where it errors out when I click on Edit to disable the Insert Button;
Dim btn1 As Button = DirectCast(cmditm.FindControl("AddNewRecordButton"), Button)  
                btn1.Enabled = False 
                Dim lnkbtn1 As LinkButton = DirectCast(cmditm.FindControl("InitInsertButton"), LinkButton)  
                lnkbtn1.Enabled = False 
Thank you again for all your help,
Shehab
0
Yavor
Telerik team
answered on 19 Aug 2008, 05:20 AM
Hi Shehab,

Attached to this message, is a small application, which handles the requested functionality.
I hope it helps.

Best wishes,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Shehab
Top achievements
Rank 1
answered on 19 Aug 2008, 11:55 AM
Hi Yavor,

Thank you very much for your help. I tried the project and I saw it hides the Add New button when editing and then it won't show it again until page post back and same thing in Adding new item; it hides the edit from everywhere else on the page. I just want to be able to enable and disable the buttons not hide it until the page is refreshed. Thanks again.

Shehab
0
Accepted
Yavor
Telerik team
answered on 20 Aug 2008, 09:51 AM
Hello Shehab,

Attached to this message, is a modification of the sample sent earlier, to cater for the functionality in question.
I hope it helps.

All the best,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Shehab
Top achievements
Rank 1
answered on 20 Aug 2008, 10:52 AM
Yavor, thank you very much, that is exactly what I needed.
Thanks again,
Shehab
0
Jeff
Top achievements
Rank 1
answered on 30 Oct 2008, 05:51 PM
Hello,

This works for me, but I still need to disable the + sign gif that acts as a link to add a new record also. Any ideas?
0
Sebastian
Telerik team
answered on 31 Oct 2008, 06:48 AM
Hi Jeff,

You can disable or completely remove the [Add new record] button by defining your own command item template. Review the following article from the online documentation for more details:

http://www.telerik.com/help/aspnet-ajax/grdcommanditemtemplate.html

Best regards,
Stephen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Kalpna
Top achievements
Rank 1
answered on 29 Jun 2013, 04:52 AM
Hello..
I have an problem in Add new record button. I hide this button by coding on PreRender Event of rad grid..but the + sign is still shown..i want to remove that..and i also set AddNewRecordText="". In command item setting of radgrid, i only want refresh button..neither a add new record text nor a + sign. Please help me.
0
Princy
Top achievements
Rank 1
answered on 01 Jul 2013, 04:23 AM
Hi kalpna,

Can you be more specific what you are exactly trying to acquire?If you want to hide the AddNewRecord button simple set it to false on CommandItemSettings as shown below.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" >
    <MasterTableView CommandItemDisplay="Top">              
      <CommandItemSettings ShowAddNewRecordButton="false" />    
    </MasterTableView>   
. . . . . . . . . . .         
</telerik:RadGrid>

Or you can set the CSS property of the "+" sign as below,if you want to hide only that symbol.

CSS:
<style type="text/css">
    .RadGrid .rgAdd
    {         
        visibility: hidden;
    }
</style>


Thanks,
Princy
Tags
Grid
Asked by
Shehab
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Stewart Ellis
Top achievements
Rank 1
Cres
Top achievements
Rank 1
Shehab
Top achievements
Rank 1
Yavor
Telerik team
Jeff
Top achievements
Rank 1
Sebastian
Telerik team
Kalpna
Top achievements
Rank 1
Share this question
or