我们正在尝试从 GridView 中获取 HTML 并将其存储到 String 中,以便字符串可以用作电子邮件的正文。
到目前为止,我们已经在代码隐藏中使用了这种编码:
Protected Sub EmailStudentList()
' Get the rendered HTML.
'-----------------------
Dim SB As New StringBuilder()
Dim SW As New StringWriter(SB)
Dim htmlTW As New HtmlTextWriter(SW)
GridViewSummary.RenderControl(htmlTW)
' Get the HTML into a string.
' This will be used in the body of the email report.
'---------------------------------------------------
Dim dataGridHTML As String = SB.ToString()
MsgBox(Server.HtmlEncode(dataGridHTML))
End Sub
当应用程序运行时,会显示此错误:
Control 'BodyPlaceholder_GridViewSummary' of type 'GridView' must be placed
inside a form tag with runat=server.
所以我在标记中的这个位置放置了一个表单标签:
<asp:Content
ID="ContentBody"
ContentPlaceHolderID="BodyPlaceholder"
runat="server">
<form runat="server">
现在我们得到这个错误:
A page can have only one server-side Form tag.
标记中的其他任何地方都没有其他表单标签。
这是 GridView 的标记:
<asp:GridView
ID="GridViewSummary"
runat="server"
AllowPaging="True"
AllowSorting="True"
AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="Surname" HeaderText="Last Name" SortExpression="Surname" />
<asp:BoundField DataField="Forename" HeaderText="First Name" SortExpression="Forename" />
<asp:BoundField DataField="ParentName" HeaderText="Parents" SortExpression="ParentName" />
</Columns>
</asp:GridView>