Invoke "Add new record" on a custom button

3 posts, 0 answers
  1. Basharat
    Basharat avatar
    8 posts
    Member since:
    Dec 2012

    Posted 28 Feb 2013 Link to this post

    Hi,

    I have a RadGrid working where on add and edit events a user control is defined to be used for user inputs.
    Now I have a scenario where I want to clone one of the record from a button (placed on that user control).
    When user clicks clone button, I want to fire up the "Add new record" event of RadGrid and populate data from the source record so the user may change some values and click save to clone the record.

    I cannot find a way to fire the "Add new record" event from a custom button on the usercontrol. Any help ideas to achieve this are appreciated.

    Thanks,
    Bash
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 28 Feb 2013 Link to this post

    Hi,

    Try the following code.
    C#:
    protected void Button2_Click(object sender, EventArgs e)
    {
          RadGrid grid = (this.FindControl("RadGrid1") as RadGrid);
         (grid.MasterTableView.GetItems(GridItemType.CommandItem)[0] as GridCommandItem).FireCommandEvent(RadGrid.InitInsertCommandName, string.Empty);
    }

    Thanks,
    Shinu
  3. Mark
    Mark avatar
    7 posts
    Member since:
    Nov 2018

    Posted 23 Jul in reply to Shinu Link to this post

    This is perfect, and just what i was looking for.  There are a lot of solutions on this board about firing Command Events programatically, but they all have the form:

    if (radGrid1.Items.Count > 0)

    {

     radGrid1.Items[0].FireCommandEvent("InitInsert", "");

    }

    which works great as long as you actually have 1 or more items.  The Add New Record button should be callable regardless of how many items are in the grid, and this solution does exactly that!

    Thanks!

    MK

Back to Top