Cannot apply indexing with [] to an expression of

2019-07-29 23:42发布

问题:

I am getting Error 'Cannot apply indexing with [] to an expression of type 'ISet''

for this code snippet

foreach (GridViewRow grv in customTableDataList.UniGrid.GridView.Rows)
{
  if (grv != null)
  {
    if (null != grv.FindControl(ItemCheckBoxID) && ((CheckBox)grv.FindControl(ItemCheckBoxID)).Checked)
    {
      //At this line I am getting error.
      itemIds += customTableDataList.UniGrid.ActionsID[rowCounter] + ", ";  
    }
    rowCounter++;
  }
}

Can anyone give some more details to resolve this.

回答1:

Add new using:

System.Linq;

and change

foreach (GridViewRow grv in customTableDataList.UniGrid.GridView.Rows)
{
  if (grv != null)
  {
    if (null != grv.FindControl(ItemCheckBoxID) && ((CheckBox)grv.FindControl(ItemCheckBoxID)).Checked)
    {
      itemIds += customTableDataList.UniGrid.ActionsID.ToArray()[rowCounter] + ", ";
    }
    rowCounter++;
  }
}