1

So I'm retrieving data from two different lists, (questions and answers), and want to print out the first question and then the first answer. I'm trying with for loops, but it's not working out. Any suggestions? Thanks!

foreach (SP.ListItem listItem in jobQuestionnaires) { 
    foreach (SP.ListItem listItemTwo in answers) { 
        Label1.Text = Label1.Text + " " + listItem["QuestionText"]; 
        Label1.Text = Label1.Text + " " + listItemTwo["Answer"]; 
    } 
}
  • Post relevant code what you have tried so far – Amal Hashim Nov 4 '14 at 19:46
  • <code>foreach (SP.ListItem listItem in jobQuestionnaires) { foreach (SP.ListItem listItemTwo in answers) { Label1.Text = Label1.Text + " " + listItem["QuestionText"]; Label1.Text = Label1.Text + " " + listItemTwo["Answer"]; } }</code> – Adrian Nov 4 '14 at 19:53
  • I'm sorry, I can't figure out how to put this in proper indentation. – Adrian Nov 4 '14 at 19:57
  • Can you explain what is not working? – Amal Hashim Nov 4 '14 at 20:05
  • @Adrian Edit the original post. – Slaven Semper Nov 4 '14 at 20:07
0

Try this

for(int index = 0; index < jobQuestionnaires.Count; index++) {
    Label1.Text = Label1.Text + " " + jobQuestionnaires[index]["QuestionText"]; 
    Label1.Text = Label1.Text + " " + answers[index]["Answer"];
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.