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

cancel grid edit/insert mode from a button outside the grid

8 Answers 389 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vinhlan
Top achievements
Rank 1
Vinhlan asked on 05 May 2008, 12:09 AM

Hi,

I've got the requirement to cancel grid edit/insert mode from a button outside the grid.  Please, advise whether this can be done.

Thanks
Vinhlan

8 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 05 May 2008, 06:27 AM
Hi,

Try the following code snippet to achieve the desired scenario.

CS:
 protected void Button1_Click(object sender, EventArgs e) 
    { 
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items) 
        { 
            RadGrid1.MasterTableView.ClearEditItems(); 
            item.OwnerTableView.IsItemInserted = false
        } 
    } 


Thanks
Shinu.
0
Vinhlan
Top achievements
Rank 1
answered on 06 May 2008, 05:47 AM
Hi Shinu,

I tried the code snippet that you provided.  However, it did not work.

Thanks,
Vinhlan
0
Kiara
Top achievements
Rank 1
answered on 06 May 2008, 11:11 AM
Add a Rebind() method call at the bottom of the provided code snippet:

 protected void Button1_Click(object sender, EventArgs e)  
    {  
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items)  
        {  
            RadGrid1.MasterTableView.ClearEditItems();  
            item.OwnerTableView.IsItemInserted = false;  
            RadGrid1.MasterTableView.Rebind(); 
        }  
    }  

Kiara
0
Vinhlan
Top achievements
Rank 1
answered on 08 May 2008, 01:52 AM
Hi Kiara,

I've tried that too.  However, it still did not work.

Thanks,
Vinhlan
0
Yavor
Telerik team
answered on 08 May 2008, 05:06 AM
Hi Vinhlan,

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

Kind regards,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Princy
Top achievements
Rank 2
answered on 08 May 2008, 06:03 AM
Hi Vinhlan,

You can also try the following line of code to clear the edit items on clicking the  button.

CS:
RadGrid1.EditIndexes.Clear();  
        RadGrid1.Rebind();  
 


Thanks
Princy.
0
chris
Top achievements
Rank 1
answered on 10 Feb 2009, 09:59 PM
This is old but i was looking for the same thing and everybody here has server side examples. You can also do it from JavaScript
My button
<id="A1" href="#" runat="server" onclick="SwitchGridInInsertMode();return false;" class="newButton"
            <span>Add</span></a

The javascript
function SwitchGridInInsertMode() 
  var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView(); 
  masterTable.showInsertItem(); 
}  


0
Princy
Top achievements
Rank 2
answered on 13 Feb 2009, 06:19 AM
Hi Chris,

You can call the  fireCommand mehod which triggers specific command for the grid when executed.

JavaScript:
<script type="text/javascript"
function addnew() 
    var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView(); 
    masterTable.fireCommand("InitInsert",""); 
</script> 

or also use the insertItem() method to purt the grid in insert mode.

function AddNewItem()
{
  var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
  masterTable.insertItem();
}

Thanks
Princy
Tags
Grid
Asked by
Vinhlan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Vinhlan
Top achievements
Rank 1
Kiara
Top achievements
Rank 1
Yavor
Telerik team
Princy
Top achievements
Rank 2
chris
Top achievements
Rank 1
Share this question
or