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

Collection was modified; enumeration operation may not execute

1 Answer 130 Views
Grid
This is a migrated thread and some comments may be shown as answers.
KK
Top achievements
Rank 1
KK asked on 05 Aug 2014, 09:38 AM
Hello telerik support,

In my case, The grid allow users to check the GridClientSelectColumn (CheckBox) for multiple deletion

after users selected all columns that they want to delete, they can press delete button to delete the selected records.

In core behind im going to save the GridDataItem in the List<GridDataItem> and using foreach loop to run FireCommandEvent

foreach (GridDataItem item in deleteList)
            {
                item.FireCommandEvent("Delete", string.Empty);
            }


However, the loop can only delete one record on the list.

After that, i try to use FireCommandEvent in immediate window and it return "expression has been evaluated and has no value"

May i ask if there is any solution so solve this problem?


Thanks,
KK






1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 05 Aug 2014, 12:21 PM
Hi,

I guess you are having a delete button in CommandItemTemplate of your grid, and using GridClientSelectColumn, you want to delete the selected items. You can use the CommandName DeleteSelected for the button and it will fire the DeleteCommand event. There you can loop through the selected rows and perform delete. Provide your full code snippet if this doesn't help.

ASPX:
<CommandItemTemplate>
<asp:Button ID="btnDelete" runat="server" Text="Delete Selected" CommandName="DeleteSelected" />
</CommandItemTemplate>

C#:
void rgrdSample_DeleteCommand(object sender, GridCommandEventArgs e)
{
  //Loop through selected rows
  foreach (GridDataItem item in rgrdSample.SelectedItems)
  {
    //Get the datakey value of selected rows
    string ID = item.GetDataKeyValue("ID").ToString();
    //code to delete 
  }
}

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