In the Web program, the data source binding control GridView contains a template column. It is very easy to obtain whether the check box is selected and the row where the check box is located. The classic code is as follows: For (int I = 0; I <gvList. Rows. Count; I ++) { If (CheckBox) gvList. Rows [I]. Cells [0]. FindControl ("chkID"). Checked) {} } However, the DataGridView control in WinForm cannot be used in this way. The DataGridView control does not have a free template column at all. Some have six built-in template columns, and the check box is one of them. To obtain whether or not the check box is selected and other values corresponding to the selected row cannot be implemented in this way in the Web program, but must be determined by the Value attribute of Cells in the DataGridView control. (In WinForm, The DataGridView control deletes multiple records through the check box.) The Code is as follows: Private void btnDelete_Click (object sender, EventArgs e) { String strNames = "you selected :"; For (int I = 0; I <dgvList. Rows. Count; I ++) { If (dgvList. Rows [I]. Cells [0]. Value! = Null) // determine whether the check box for this row exists { If (dgvList. Rows [I]. Cells [0]. Value. ToString () = "True") // you can check whether the check box is selected. { StrNames + = dgvList. Rows [I]. Cells [2]. Value. ToString () + ""; } } } MessageBox. Show (strNames, "system prompt", MessageBoxButtons. OK, MessageBoxIcon. Information ); } Running result: |
Reposted from the network. The source is unknown !!