我所做的:
Panel p = new Panel();
p.Attributes["class"] = "resultview";
foreach (string st in summary)
{
Panel answerPanel = new Panel();
Label answerLbl = new Label();
answerLbl.Text = theAnswer;
answerPanel.Controls.Add(answerLbl);
answerPanel.Attributes["class"] = "answer";
//answerPanel.Controls.Add(new LiteralControl(theAnswer)); //Also tried this instead of a label
p.Controls.Add(answerPanel);
}
我在两个循环后得到:
<div class="resultview">
<div class="answer">
<span>
<div class="ExternalClass10FA632A5FA34598A2540E2A29E38841">Yes</div>
<div class="answer"><span>No</span></div>
</span>
</div>
</div>
两个循环后我想要什么:
<div class="resultview">
<div class="answer"><span>Yes</span></div>
<div class="answer"><span>No</span></div>
</div>
所以我的问题是为什么第二个“ div class=answer
”会嵌套在第一个中。为什么会有“ div class="ExternalClass...
”?更重要的是,我该怎么做才能让自己看起来像我想要的那样?