0

我有一个 vb.net 函数,我正在做一些事情,它返回一个 gridview 以在电子邮件中发送它。问题是当我在电子邮件中调用该函数时,即使函数没有返回任何内容,也会发送电子邮件。我根本不发送空白电子邮件。我想当函数什么都不返回时,它不应该发送电子邮件。这是我的功能

Public Function emaildata(ByVal grdv As GridView, ByVal chk As String, ByVal celpos As Integer) As GridView
        Dim comm As OleDbCommand = New OleDbCommand()
        Dim bpv As String = ""
        Dim gv As New GridView
        For Each gvrow As GridViewRow In grdv.Rows
            Try
                Dim rdobtn As RadioButtonList = CType(gvrow.FindControl(chk), RadioButtonList)
                If rdobtn.SelectedValue.Equals("5") Or rdobtn.SelectedValue.Equals("1") Or rdobtn.SelectedValue.Equals("6") Or rdobtn.SelectedValue.Equals("4") Or rdobtn.SelectedValue.Equals("2") Then
                    If bpv <> "" Then
                        bpv += ","
                    End If
                    bpv += gvrow.Cells(celpos).Text
                    comm.CommandText = "SELECT row_number() over(order by rownum) Sr, to_char(chq_num) Cheque#,to_char(bpv_amt,'9,999,999,999') Amount,vch_nar Narration,bnf_nam PartyName,acc_des Bank from  CHECK_DATA where bpv_num in(" & bpv.ToString() & ") and BPV_DTE=to_date('" & TreeView2.SelectedValue & "') union all SELECT null,'Total :',to_char(sum(bpv_amt),'9,999,999,999') Amount,null,null,null from  CHECK_DATA where bpv_num in(" & bpv.ToString() & ") and BPV_DTE=to_date('" & TreeView2.SelectedValue & "')"
                    comm.CommandType = CommandType.Text
                    comm.Connection = con
                    Dim da As New OleDbDataAdapter(comm)
                    Dim ds As New DataSet
                    da.Fill(ds)
                    gv.DataSource = ds
                    gv.DataBind()
                End If
            Catch ex As Exception
                Response.Write("There is Problem In Cheque Approval System Please Contact With IT")
            End Try
        Next
        Return gv
    End Function

我在电子邮件功能中将其称为这样的主题

email("malik.adeel@shakarganj.com.pk", "[Cheque Approval] GM Finance Reviewed (" & TreeView2.SelectedValue & ")" & subsmcnt(GridView5, "chkStatusGM", 4), gridhtm(emaildata(GridView5, "chkStatusGM", 4)))

emaildata(GridView5, "chkStatusGM", 4)如果不返回任何电子邮件,我该怎么做?

4

1 回答 1

2

可能最简单的方法是检查GridView包含属性:GridViewRowsCount

Dim grdEmail = emaildata(GridView5, "chkStatusGM", 4)
If grdEmail.Rows.Count > 0
    email("malik.adeel@shakarganj.com.pk", 
          "[Cheque Approval] GM Finance Reviewed (" & TreeView2.SelectedValue & ")" & subsmcnt(GridView5, "chkStatusGM", 4), 
          gridhtm(grdEmail))
End If 
于 2012-12-17T09:32:31.857 回答