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

How to add Batch Edit Event Handler Programmatically

1 Answer 112 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 22 Jul 2014, 01:38 PM
Dear Telerik,

I've generated a radgrid programmatically, which includes to enable batch editing and command as below, but my RadGrid_BatchEditCommand never fires? Appreciate for any hints.
for (int i = 0; i<10; i++0)
{
strategy = strategy + Convert.ToString(i);
                RadGrid RadGrid_Strategy = new RadGrid();
                RadGrid_Strategy.ID = strategy;
                RadGrid_Strategy.Skin = "Office2010Blue";
                RadGrid_Strategy.GridLines = System.Web.UI.WebControls.GridLines.Both;
                RadGrid_Strategy.DataSource = GetDataTableForStrategy(CY, i);
                RadGrid_Strategy.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
                RadGrid_Strategy.ShowHeader = false;
                RadGrid_Strategy.BatchEditCommand += new GridBatchEditEventHandler(RadGrid_BatchEditCommand);
                RadGrid_Strategy.MasterTableView.EditMode = GridEditMode.Batch;
                RadGrid_Strategy.MasterTableView.BatchEditingSettings.EditType = GridBatchEditingType.Cell;
                RadGrid_Strategy.AllowAutomaticUpdates = true;
                RadGrid_Strategy.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = false;
                RadGrid_Strategy.MasterTableView.CommandItemSettings.ShowSaveChangesButton = true;
                RadGrid_Strategy.MasterTableView.CommandItemSettings.ShowCancelChangesButton = true;
                PlaceHolder1.Controls.Add(RadGrid_Strategy);
                RadGrid_Strategy.Rebind();
}

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 23 Jul 2014, 05:33 AM
Hi Tim,

I guess you are creating many RadGrid in a page. Please remove Rebind() from the loop and use NeedDataSource event to bind your Grids. The BatchEditCommand command fires successfully at my end once the Save button is clicked.

C#:
{
 for (int i = 0; i < 10; i++)
  {
    strategy = strategy + Convert.ToString(i);
    RadGrid RadGrid_Strategy = new RadGrid();
    RadGrid_Strategy.ID = strategy;
    // Your Codes
    RadGrid_Strategy.NeedDataSource += new GridNeedDataSourceEventHandler(RadGrid_Strategy_NeedDataSource); 
    RadGrid_Strategy.BatchEditCommand += new GridBatchEditEventHandler(RadGrid_Strategy_BatchEditCommand);
   //  Your Codes
    PlaceHolder1.Controls.Add(RadGrid_Strategy);
  }
}
void RadGrid_Strategy_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    RadGrid RadGrid_Strategy = (RadGrid)sender;
    RadGrid_Strategy.DataSource =GetDataTableForStrategy(CY, i);
}

Thanks,
Princy
Tags
Grid
Asked by
Tim
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or