I have a product admin web site that has been generated using ASP.NET Dynamic Data and Entity Framework 4.1 (Code First).
I've started creating a way of bulk editing rows. I have the edit controls for the columns I want to be able to bulk edit (I've created a new attribute called EditableInBulk that I decorate my properties with). I have also added a new column in the GridView with a checkbox that indicates if the row should be bulk edited or not.
The thing left now is I need to programmatically update the rows that I've checked with "Edit".
Here's the code that I use to find the rows that have been checked, the thing missing is to actually update the data and persist.
// Find all items that will be edited
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowType != DataControlRowType.DataRow)
continue;
// Fetch the item index of the rows that has "Edit" checked
var editMe = row.Cells[1].Controls.OfType<CheckBox>().Any(ch => ch.Checked);
if (editMe)
{
// Edit the fields in the row and persist
}
}
I should be able to use the UpdateRow method in the GridView control. But before that I need to update the fields within the row.
Does anyone have a clue on how I could achieve this?
The thing is also is that it needs to be generic. Should work with every entity type that has columns that I've decorated with my custom attribute "EditableInBulk". So there can't be any entity specific persisting going on.
I've started to modify the List.aspx file that comes with the Dynamic Data project.