Toggle "SelectedInd" to true based on grid0 filter

I have a datagrid called grid0 and within the data there is a boolean/bit column called SelectedInd.

Basically, what I want to do is

  1. Define a button called Select All Filtered.
  2. The button invokes code that sets SelectedInd = 1/true for only the rows that are in grid0.view.

Okay I actually figured this out.

foreach (Models.Mcpdb.TblScenarioWorkcenter row in grid0.View)
{
row.SelectedInd = true;
}

Works beautifully.

I have to follow up with a different question.

I tried to implement a Save button that loops through each row of the data grid (like above) and invokes the updateTblScenarioWorkcenter method in the data services controller cs. When I implement this, it gives me the error that there is already an in progress connection. Is there a way to achieve what I’m describing?

I actually figured this out too and will share my code in case others have a similar problem.

I made a save button and used this code:

var grid = this.grid0;
for(int i = 0; i<= grid.Data.Count()-1;i++ )
{
await grid.UpdateRow(grid.Data.ElementAt(i));
};

And on RowUpdate() I use the code that is already generated when you do a DataGrid InLine Edit page. I ran into errors when I tried to use a foreach loop, and it seems that the problems with foreach is well documented in this SO link c# - SqlException from Entity Framework - New transaction is not allowed because there are other threads running in the session - Stack Overflow

Hopefully this helps someone.

For future improvement, I will make an "updated" column that sets to true when a field is changed so that we only post changes to the updated rows.