You can determine whether the check box is checked by using the standard approach for getting a control value from a template column — getting an object from the Controls collection of the cell and casting it appropriately. If you are getting a Checkbox control, remember that it is usually the second control (index 1) because a literal control precedes it (even if it is blank). If you are deleting, you must do so by key and not by offset in the dataset. The index of an item in the DataGrid control might not match the index of the same record in the table. Even if it does at first, after the first record is deleted it will not. Here, the code gets the record key out of the grid's DataKey collection. It then uses the FindBy<key> method in the dataset table to locate the record to delete. After the records have been deleted from the dataset (technically, they are only marked for deletion), you delete them from the database by calling the data adapter's Update method. The code then refreshes the dataset from the database and re-binds the grid. Editing Multiple Rows At Once The standard way to edit rows in the DataGrid control — by adding an "Edit, Update, Cancel" button to the grid's columns — only allows users to edit one row at a time. If users want to edit multiple rows, they must click the Edit button, make their changes, and then click the Update button for each row.
In some cases, a useful alternative is to configure the grid so that it is in edit mode by default. In this scenario, the grid always displays editable data in text boxes or other controls; users do not explicitly have to put the grid into edit mode. Typically, users make whatever changes they want and then click a button (not a button in the grid) to submit all changes at once. The page might look something like the following:
Figure 1
You can use this style of editing grid with any data model, whether you are working against a dataset or directly against the data source using data commands.
To configure the grid for multiple-row edit, add the columns as you normally would and convert all editable columns to template columns. In the Columns tab of the grid's Property Builder, select the column and at the bottom of the window, choose Convert this column into a Template column. To edit the templates, right-click the grid and choose Edit Template.
Add the edit controls to the ItemTemplate. Note that you are not adding them to the EditItemTemplate, as you normally would, because the rows will not be displayed in edit mode. That is, the ItemTemplate will contain editable controls.