2

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>      
4

1 に答える 1

5

ページに次のサブを追加して、再試行してください。

Public Overrides Sub VerifyRenderingInServerForm(control As Control)
    Return
End Sub

編集:

イベントの検証を無効にするには、EnableEventValidation="False" を aspx ページのディレクティブに追加します。例えば

<%@ Page EnableEventValidation="False" %>
于 2012-11-27T18:00:04.427 に答える