无法获取 asp:DataGrid ID 中的行值

Not able to get Rows values in asp:DataGrid ID

我有一个如下所示的 asp 数据网格

<asp:DataGrid ID="dgRegions" runat="server">

现在我想访问 "Submit" 按钮点击时每一行的列值,我尝试使用下面的代码

foreach (GridViewRow r in dgRegions.Rows)
{
}

但 Rows 没有得到解决并说明 "Datagrid does not contain a definition of 'Rows'" 这里有什么问题?

如果您使用的是 DataGrid,则可以在项目 属性 中获取记录集合。

  foreach (DataGridItem item in dataGrid.Items)
  { 
     //...
     var data = item.Cells[0].Text;

     //or
     CheckBox chkBox = (CheckBox)item.FindControl("MyCheckBox");
     if (chkBox.Checked)
     {
         // do something
     }
  }

DataGridView 有 Rows property and DataGrid has Items 属性 用于记录收集。