2

우리는 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. 

그래서이 위치에 양식 태그를 배치 마크 업 :

<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>  
+0

마스터 페이지를 사용하고 있습니까? – mcalex

+0

예, 우리는 그렇게하고 있습니다. –

+0

누락 된 양식 컨트롤은 마스터 페이지에서 찾을 수 있습니다. 어쩌면'runat = "server"'속성이 누락되었을 수도 있습니다. – mcalex

답변

5

추가 다음 하위 다시 시도 :

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

편집 :

이벤트 유효성 검사를 해제하려면, 단지 추가 EnableEventValidation = "False"aspx 페이지의 지시문에. 예 :

<%@ Page EnableEventValidation="False" %> 
+0

Vano 코딩에 감사드립니다. 추가 한 후에는이 오류가 표시됩니다. RegisterForEventValidation은 Render(); 어떻게해야합니까? –

+0

수정 된 답변보기 –

+0

감사합니다. Vano. 나는 그것을 넣었고 완벽하게 작동했습니다. :-) –