根据相同的ID,通过xml合并多行,并在页面里解码显示出来

1.通过SQL拼写出要显示字符串:
 SELECT * ,(sa.AnswerContent+'<BR/>'+ISNULL(saaaa.XMLAnswerContent,'')) AS XMLAnswerContent2
 FROM SeAnswer sa
 JOIN mdList ml ON sa.AnswerType=ml.[value]
 AND ml.[type]='AnswerType'
 AND sa.AnswerType = ISNULL(@AnswerType,sa.AnswerType)
 AND sa.AnswerContent LIKE @AnswerContent+'%'
 LEFT JOIN
 (
  SELECT DISTINCT saa.AnswerID,
  (
   SELECT '<br/>'+sq.Question+'>>'+sqo.ChooseItem FROM SeAnswer saaa
   JOIN SeAnswerQuestionRelation saqr ON saqr.AnswerID=saaa.AnswerID
   JOIN SeQuestion sq ON sq.QuestionID=saqr.QuestionID
   JOIN SeQuestionOption sqo ON sqo.QuestionOptionID = saqr.QuestionOptionID
   AND saaa.AnswerID=saa.AnswerID
   FOR XML PATH('')
  ) AS XMLAnswerContent
  FROM SeAnswer saa
 )saaaa ON sa.AnswerID = saaaa.AnswerID
 ORDER BY sa.LastEditDate DESC

 

eg: &lt;br/&gt;该顾客的排便情况如何?&gt;&gt;A、1天至少1次,很顺畅

 

2.页面显示时进行解码操作:
                <asp:TemplateField>
                    <HeaderTemplate>诊断问题</HeaderTemplate>
                    <ItemTemplate><span id="spanxml" runat="server"><%# Server.HtmlDecode(Eval("XMLAnswerContent2").ToString())%></span></ItemTemplate>
                </asp:TemplateField>

posted @ 2012-03-14 21:10  iewysdcwy  阅读(303)  评论(0编辑  收藏  举报