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

disable the Add New Link

3 Answers 210 Views
Grid
This is a migrated thread and some comments may be shown as answers.
TippCityTom
Top achievements
Rank 1
TippCityTom asked on 23 Jan 2009, 05:24 PM
how can you disable the Add New Link until edit is updated   I don't want user to be able to add a record if they are currently updating one at the same time   I assume this is done via RadGrid1_ItemCommand


Using:

 

<CommandItemSettings AddNewRecordText="Add new record" AddNewRecordImageUrl="Images/AddRecord.gif"

 

 

RefreshText="Refresh" RefreshImageUrl="Images/Refresh.gif" />

 

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 23 Jan 2009, 06:04 PM
Hello Thomas,

I suggest you test the following approach:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    bool editMode = e.Item.OwnerTableView.OwnerGrid.EditIndexes.Count > 0; 
    bool insertMode = e.Item.OwnerTableView.IsItemInserted; 
    if ((e.CommandName == RadGrid.InitInsertCommandName ||  
        e.CommandName == RadGrid.EditCommandName ||  
        e.CommandName == RadGrid.EditAllCommandName ||  
        e.CommandName == RadGrid.EditSelectedCommandName) 
        && (insertMode || editMode)) 
        e.Canceled = true

Let me know whether this helps.

Best regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
TippCityTom
Top achievements
Rank 1
answered on 23 Jan 2009, 06:47 PM

thanks for the fast response, that particular answer I could not get to work for me and I assume it is because I set AllowAutomatic Inserts/Updates =  false

do you have one for scenario where they are done manually, sorry should have clarified that initially?

in my case IsInEditMode is always false

0
Accepted
Shinu
Top achievements
Rank 2
answered on 27 Jan 2009, 10:12 AM
Hi Thomas,

Can you try with the following approach and see if it is helpful.

CS:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
      // this will fire when the edit button is clicked and disable the AddNewRecord button when the Grid is in edit mode
        if ((e.Item is GridEditableItem)&&(e.Item.IsInEditMode)) 
        { 
            foreach (GridCommandItem cmdItm in RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)) 
            { 
                LinkButton Addbtn = (LinkButton)cmdItm.FindControl("InitInsertButton"); 
                Addbtn.Enabled = false
                Button btn = (Button)cmdItm.FindControl("AddNewRecordButton"); 
                btn.Enabled = false
            } 
        } 
   } 



Thanks
Shinu.
Tags
Grid
Asked by
TippCityTom
Top achievements
Rank 1
Answers by
Daniel
Telerik team
TippCityTom
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or