我们试图从GridView获取HTML并将其存储到字符串中,以便可以将字符串用作电子邮件的正文。将ASP.Net 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.
所以我放在一个表单标签在这个位置在标记:
现在我们得到这个错误:
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>
您是否正在使用母版页? – mcalex
是的,我们正在那样做。 –
您可能会在母版页中找到您缺少的表单控件。也许它缺少'runat =“server”'属性 – mcalex