-
November 14th, 2011, 05:02 PM
#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.
-
November 15th, 2011, 06:25 AM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|