Problem looping through CheckBox value in DataGrid

  • Thread starter Thread starter Stephan Bour
  • Start date Start date
S

Stephan Bour

I was playing with this simple code strait from MSDN and I got the following
compile error:
³foreach statement cannot operate on variables of type
'System.Web.UI.WebControls.DataList' because
'System.Web.UI.WebControls.DataList' does not contain a definition for
'GetEnumerator', or it is inaccessible"

protected void UpdateNewOligos (Object sender, EventArgs e) {
int rowCount = 0;
StringBuilder gridSelections = new StringBuilder();
foreach (DataListItem NewOrdersDataListItem in NewOrdersDataList) {
CheckBox chkSelectNew =
(CheckBox)NewOrdersDataListItem.Cells[0].Controls[1];
if (chkSelectNew.Checked == true) {
rowCount++;
gridSelections.AppendFormat("The checkbox for [0] was
selected<br>",
NewOrdersDataList.DataKeys[NewOrdersDataListItem.ItemIndex].ToString());
}
}
gridSelections.Append("<br>");
gridSelections.AppendFormat("Total number selected is: (0)",
rowCount.ToString());
}

Any idea?
Thanks,
Stephan.
 
try a normal for loop
for(int i=0; i<NewOrdersList.Count; i++)
{
DataListItem NewOrderDataItem = NewOrdersList;
// the rest of the code...
}

Should sort out..

Hermit Dave
 
Back
Top