2012-12-17 146 views
0

我有一個vb.net函數是我正在做一些東西,它是返回一個GridView發送它在電子郵件。問題是,當我在電子郵件中調用函數即使沒有任何功能返回,也會發送電子郵件。我根本不發送空白的電子郵件。我想當函數不返回任何內容時,它不應該發送電子郵件。這裏是我的功能vb.net檢查函數是否不返回任何東西

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("[email protected]", "[Cheque Approval] GM Finance Reviewed (" & TreeView2.SelectedValue & ")" & subsmcnt(GridView5, "chkStatusGM", 4), gridhtm(emaildata(GridView5, "chkStatusGM", 4))) 

一個問題,我怎麼能做到這一點,如果emaildata(GridView5, "chkStatusGM", 4)回到什麼郵件不應發送?

回答

2

也許最簡單的是檢查是否GridView包含GridViewRowsCount屬性:

Dim grdEmail = emaildata(GridView5, "chkStatusGM", 4) 
If grdEmail.Rows.Count > 0 
    email("[email protected]", 
      "[Cheque Approval] GM Finance Reviewed (" & TreeView2.SelectedValue & ")" & subsmcnt(GridView5, "chkStatusGM", 4), 
      gridhtm(grdEmail)) 
End If 
+0

嗯好主意,讓我先檢查 – user1820339

相關問題