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

Insert Grid Item from outside button

2 Answers 81 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Philip Senechal
Top achievements
Rank 1
Philip Senechal asked on 30 Oct 2010, 12:43 AM
Hey guys,

I'm using a RadGrid as my input form and everything is working to open a blank record in the editform and fill it out.

I'm using a button outside the grid to kick off the insert command. This is the code that I have to kick off the update command in another grid...

GridItem[] items1 = RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem);
for (int i = 0; i < items1.Length; i++)
{
    int itemIndex = items1[i].ItemIndex;
    if (RadGrid1.EditItems[0].ItemIndex == itemIndex)
    {
        (items1[i] as GridEditableItem).FireCommandEvent("Update", String.Empty);
    }
}

but it doesn't work by changing the command to Insert. The error I'm getting is in regards to the itemIndex which makes sense because it shouldn't have an index yet.

Can you show my how to get reference to the InsertItem using an outside button so I can kick off the Insert command?

Thanks =)

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 01 Nov 2010, 06:15 AM
Hello Philip,

You can use following code snippet to get reference to the GridEditFormInsertItem.

C#:
protected void Button1_Click(object sender, EventArgs e)
    {
        GridEditFormInsertItem insertItem = (GridEditFormInsertItem)RadGrid1.MasterTableView.GetInsertItem(); // accessing grid insert item
        insertItem.FireCommandEvent("PerformInsert", String.Empty);
    }

Thanks,
Princy.
0
Philip Senechal
Top achievements
Rank 1
answered on 01 Nov 2010, 07:34 PM
Thank you sir...works perfectly!
Tags
Grid
Asked by
Philip Senechal
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Philip Senechal
Top achievements
Rank 1
Share this question
or