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

9 posts, 0 answers
  1. Vinhlan
    Vinhlan avatar
    10 posts
    Member since:
    Oct 2007

    Posted 04 May 2008 Link to this post

    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

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 05 May 2008 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Vinhlan
    Vinhlan avatar
    10 posts
    Member since:
    Oct 2007

    Posted 06 May 2008 Link to this post

    Hi Shinu,

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

    Thanks,
    Vinhlan
  5. Kiara
    Kiara avatar
    309 posts
    Member since:
    Jul 2006

    Posted 06 May 2008 Link to this post

    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
  6. Vinhlan
    Vinhlan avatar
    10 posts
    Member since:
    Oct 2007

    Posted 07 May 2008 Link to this post

    Hi Kiara,

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

    Thanks,
    Vinhlan
  7. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 08 May 2008 Link to this post

    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
  8. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 08 May 2008 Link to this post

    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.
  9. chris
    chris avatar
    25 posts
    Member since:
    Aug 2008

    Posted 10 Feb 2009 Link to this post

    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(); 
    }  


  10. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 13 Feb 2009 Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017