JQuery UI 手风琴从代码隐藏获取数据

JQuery UI Accordion getting data from codebehind

我有这个 web 应用程序,它是在 VisualStudio 2010 中创建的。

我想显示一个 "Faq" 页面,它从数据库中获取问题。 答案在服务器上的一个 txt 文件中。

所以当我从数据库中获取问题列表时,我得到了这样一个数据集:

ID = 1
Title = "Title1"
Answer = "\EN.txt"

在我的网页上有以下内容:

<div id="accordion" runat="server">        
</div>

在我的代码隐藏中,我有以下内容:

Private Sub AddQuestionToPage(row As DataRow)
    Try

        Dim headerControl = New LiteralControl()
        headerControl.Text = "<H3>" + row.Item(2) + "</H3>"
        accordion.Controls.Add(headerControl)

        Dim divcontrol = New LiteralControl()
        divcontrol.ID = "Faq_" + row.Item(0).ToString
        divcontrol.Text = GetHtmlFromFile(row.Item(3))
        accordion.Controls.Add(divcontrol)

    Catch ex As Exception
        Throw ex
    End Try
End Sub

Private Function GetHtmlFromFile(path As String) As String
    'Open a file for reading
    Dim FILENAME As String = Server.MapPath("Answers\" + path)

    'Get a StreamReader class that can be used to read the file
    Dim objStreamReader As StreamReader
    objStreamReader = File.OpenText(FILENAME)
    Dim contents As String = objStreamReader.ReadToEnd()

    Return contents

End Function

txt 文件如下所示:

<div>
<p>
    This is the english reply
</p>
<p>
    Cras dictum. Pellentesque habitant morbi tristique senectus et netus
    et malesuada fames ac turpis egestas. Vestibulum ante ipsum primis in
    faucibus orci luctus et ultrices posuere cubilia Curae; Aenean lacinia
    mauris vel est.
</p>
<p>
    Suspendisse eu nisl. Nullam ut libero. Integer dignissim consequat lectus.
    Class aptent taciti sociosqu ad litora torquent per conubia nostra, per
    inceptos himenaeos.
</p>

当我看到我的页面时,我看到的是正确的信息。 但我不认为它是手风琴。

谁能帮帮我?

divcontrol.Text = GetHtmlFromFile(row.Item(3))时,有答案的文字必须以<div>开头,以</div>结尾,否则手风琴无效。 另一种方法是在 Return contents.

之前添加额外的 html