0

我所做的:

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...”?更重要的是,我该怎么做才能让自己看起来像我想要的那样?

4

1 回答 1

0

应该提到这是一个 Sharepoint 项目。解决方案是这样的:

http://www.go4sharepoint.com/Forum/externalclass-enhanced-rich-text-fields-7091.aspx

...以及更多解释: http ://www.sp-blogs.com/blogs/adnan/Lists/Posts/Post.aspx?ID=15 。

IE:当列表在其列中选择“增强的富文本”作为文本类型时,Sharepoint 会将“div class="ExternalClass[GUID]"”添加到列表项的开头。您可以使用正则表达式摆脱它: Regex.Replace(currentItem["Your Field Name"].ToString(), "<.*?>", string.Empty);

于 2013-08-08T12:53:18.483 回答