GridViewからHTMLを取得して文字列に保存し、文字列をメールの本文で使用できるようにしようとしています。
これまで、このコーディングをコードビハインドで使用してきました。
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>