I have no idea why my foreach is not working.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: I have no idea why my foreach is not working.

  1. #1
    Join Date
    Nov 2011
    Posts
    1

    I have no idea why my foreach is not working.

    Hi all,

    I am fairly new to C# and I am trying to fix a bug.

    and I have no idea why this foreach is not working..

    protected void CQList_ItemDataBound(Object sender, DataListItemEventArgs e)
    {
    Label questionNo = (Label)e.Item.FindControl("questionNo");
    Label answerNo = (Label)e.Item.FindControl("answerNo");

    DataGrid answerGrid = (DataGrid)e.Item.FindControl("answerGrid");

    CustomQuestionCount++;
    questionNo.Text = CustomQuestionCount.ToString();
    answerNo.Text = questionNo.Text;

    Dictionary<uint, string> answers = new Dictionary<uint, string>();
    foreach (DataRow row in CustomQuestionDS.Tables[0].Select("question_id=" + ((KeyValuePair<uint, string>)e.Item.DataItem).Key))
    {
    answers[MLConvert.ToUInt32(row["answer_id"])] = (String)row["answer"];
    }


    answerGrid.DataSource = answers;
    answerGrid.DataBind();
    }

    It returns the data twice but with different IDs...weird, figured maybe someone can point me in the right direction and ect.

  2. #2
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: I have no idea why my foreach is not working.

    Can you post sample data? Maybe there are more then one answers (good and bad) for a queastion? At first look, I cannot see anything weird.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center