Problem looping through CheckBox value in DataGrid

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.
 
H

Hermit Dave

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top