Last post Nov 01, 2010 08:51 AM by gijigae
Oct 31, 2010 11:40 AM|gijigae|LINK
I have started working on a DD project and would like to know how to delete multiple rows in DD GridViews?
I have added checkboxes to a GridView in ItemTemplate, but now sure how to associate "Delete" command to a custom button?
delete gridview dynamicdata
Oct 31, 2010 07:15 PM|sjnaughton|LINK
I have done this something like this
private List<int> GetCheckedRows()
var toBeInvoiced = new List<int>();
// Get all checked row's
foreach (GridViewRow row in GridView1.Rows)
// access the check box
CheckBox invoiceEA = (CheckBox)row.FindControl("DeleteCheckBox");
if (invoiceEA != null && invoiceEA.Checked)
// Get ID
var id = Convert.ToInt32(GridView1.DataKeys[row.RowIndex]["ID"]);
The above method get me all rows that are checked and then I simply iterrate through the results and delete.
private void DeleteSelected_Click(object sender, EventArgs e)
var toBeDeleted = GetCheckedRows();
// get date context
var DC = new Models.EPCEntities();
// get row's to Invoice
var itemsToDelete = from o in DC.Orders where toBeDeleted.Contains(o.PKID)
foreach (var d in itemsToDelete)
Hope that helps
Dynamic Data 4
Nov 01, 2010 08:51 AM|gijigae|LINK
I am not sure how "Models" was played in your code, but it is good to know how to access DataContext from code-behind.