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

Invoke "Add new record" on a custom button

2 Answers 243 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Basharat
Top achievements
Rank 1
Basharat asked on 28 Feb 2013, 10:19 PM
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 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 01 Mar 2013, 04:13 AM
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
0
Mark
Top achievements
Rank 2
answered on 23 Jul 2019, 07:17 PM

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

Tags
Grid
Asked by
Basharat
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Mark
Top achievements
Rank 2
Share this question
or