1

我们在带有 GridView 的 ASP.Net Web 表单上有一个命令按钮,用户将 GridView 中显示的数据作为电子邮件发送。

在这个 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 回答