Problem looping through CheckBox value in DataGrid

Discussion in 'ASP .Net' started by Stephan Bour, Dec 11, 2003.

  1. Stephan Bour

    Stephan Bour Guest

    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.
    Stephan Bour, Dec 11, 2003
    #1
    1. Advertising

  2. Stephan Bour

    Hermit Dave Guest

    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

    "Stephan Bour" <> wrote in message
    news:BBFE5DA1.C51B%...
    > 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.
    >
    Hermit Dave, Dec 12, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Diva
    Replies:
    1
    Views:
    532
    S. Justin Gengo
    Jul 24, 2003
  2. Jim Heavey

    Looping Through Controls In DataGrid

    Jim Heavey, Dec 6, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    423
    Jim Heavey
    Dec 6, 2003
  3. Alan Silver
    Replies:
    2
    Views:
    11,028
    Alan Silver
    Jul 19, 2005
  4. Aaron
    Replies:
    2
    Views:
    509
    dhtml
    Apr 10, 2011
  5. Replies:
    5
    Views:
    263
Loading...

Share This Page