1

ユーザーが GridView に表示されたデータを電子メールとして送信する GridView を備えた ASP.Net Web フォームにコマンド ボタンがあります。

この GridView には、ユーザーがイメージ ボタンをクリックしたときに GridView から一時的に削除し、電子メールが送信されたときにボタンが再び表示されるようにする「選択」コマンド ボタンがあります。

電子メールに含めたくないボタンが電子メールにレンダリングされて表示されるため、ボタンを削除します。

ボタンなしで GridView を更新するコード ビハインド ファイルでコーディングを使用する方法を教えてください。

ボタンを示すマークアップを次に示します。

                <asp:TemplateField ShowHeader="False">
                    <ItemTemplate>
                        <asp:Button 
                            ID="ButtonSelect" 
                            runat="server" 
                            CausesValidation="False" 
                            CommandName="Select" 
                            Text="Select Schedule Item Details" />
                    </ItemTemplate>

これは、GridView の電子メールを送信するために使用しているコーディングです。

Protected Sub ImageButtonEmailThisList_Click(sender As Object, e As ImageClickEventArgs)

    ' Get the rendered HTML.
    '-----------------------
    Dim SB As New StringBuilder()
    Dim SW As New StringWriter(SB)
    Dim htmlTW As New HtmlTextWriter(SW)

    ' Remove the select button for a short while.
    '--------------------------------------------

    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()
    Dim SmtpServer As New SmtpClient()

    ObjMailMessage = New MailMessage()

    Try
        With ObjMailMessage
            .To.Add(New MailAddress(TextBoxEmailRecipient.Text))
            .Subject = "Knowledge Academy Teacher's Schdule"
            .Body = dataGridHTML
            .IsBodyHtml = True
            .DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure
        End With

        SmtpServer.Send(ObjMailMessage)

        LabelEmailMessage.Text = "<i>Email sent to " & TextBoxEmailRecipient.Text & "!</i>"

        ImageButtonEmailThisList.Visible = True

    Catch ex As Exception
        MsgBox(ex.ToString())

    Finally

        ' Refresh the GridView with select button back in place.
        '-------------------------------------------------------

    End Try

End Sub

コメント付きのセクションは、ボタンを非表示にして再度表示するためのコーディングを追加する場所を示しています。

4

1 に答える 1

3

多分あなたは列を隠すことができます:

GridViewSummary.Columns(11).Visible = False

その後 :

GridViewSummary.Columns(11).Visible = True
于 2012-12-17T15:36:14.550 に答える