Gridview Rowcommand Problem
-
In Gridview CaseNo ,HearingDate,To,CC,BCC this data is shown. CaseNo is Primary Key I am having button "SendMail" in that grid view. In gridview Rowcommand Event i write this code if i click on first row send mail command button then Label9.text get First caseno t.e. "LER/111" Simillarly i want To,CC BCC Cell value of that row How i can able to get that
Protected Sub MailDetailsGridView_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles MailDetailsGridView.RowCommand ''Code Added For The Send Mail........ If (e.CommandName = "SendMail") Then Label9.Text = e.CommandArgument.ToString() Dim row As GridViewRow row = CType(CType(e.CommandSource, Control).NamingContainer, GridViewRow) Dim email As String = CType(row.Cells(6), DataControlFieldCell).Text If (row.RowType = DataControlRowType.DataRow) Then Dim txtCCMail As TextBox Dim ToMail As String txtCCMail = row.Cells(6).Controls(0).FindControl("ToTextBox") ToMail = txtCCMail.Text End If End If End Sub
-
In Gridview CaseNo ,HearingDate,To,CC,BCC this data is shown. CaseNo is Primary Key I am having button "SendMail" in that grid view. In gridview Rowcommand Event i write this code if i click on first row send mail command button then Label9.text get First caseno t.e. "LER/111" Simillarly i want To,CC BCC Cell value of that row How i can able to get that
Protected Sub MailDetailsGridView_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles MailDetailsGridView.RowCommand ''Code Added For The Send Mail........ If (e.CommandName = "SendMail") Then Label9.Text = e.CommandArgument.ToString() Dim row As GridViewRow row = CType(CType(e.CommandSource, Control).NamingContainer, GridViewRow) Dim email As String = CType(row.Cells(6), DataControlFieldCell).Text If (row.RowType = DataControlRowType.DataRow) Then Dim txtCCMail As TextBox Dim ToMail As String txtCCMail = row.Cells(6).Controls(0).FindControl("ToTextBox") ToMail = txtCCMail.Text End If End If End Sub
Hi soniasan TRY this class
Imports System.Net.Mail
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Net
Imports System.Net.Dns
Imports System.Web.UI.Page
Imports System.Math
Imports System.Text.RegularExpressions
Imports System.Data.SqlClientPublic Class MailHelper
''' ''' Sends an mail message
'''
''' Sender address
''' Recepient address
''' Bcc recepient
''' Cc recepient
''' Subject of mail message
''' Body of mail message
Public Sub SendMailMessage(ByVal from As String, ByVal recepient As String, ByVal bcc As String, ByVal cc As String, _
ByVal subject As String, ByVal body As String)
' Instantiate a new instance of MailMessage
Dim mMailMessage As New MailMessage()' Set the sender address of the mail message mMailMessage.From = New MailAddress(from) ' Set the recepient address of the mail message mMailMessage.To.Add(New MailAddress(recepient)) ' Check if the bcc value is null or an empty string If Not bcc Is Nothing And bcc <> String.Empty Then ' Set the Bcc address of the mail message mMailMessage.Bcc.Add(New MailAddress(bcc)) End If ' Check if the cc value is null or an empty value If Not cc Is Nothing And cc <> String.Empty Then ' Set the CC address of the mail message mMailMessage.CC.Add(New MailAddress(cc)) End If ' Set the subject of the mail message mMailMessage.Subject = subject ' Set the body of the mail message mMailMessage.Body = body ' Secify the format of the body as HTML mMailMessage.IsBodyHtml = True ' Set the priority of the mail message to normal mMailMessage.Priority = MailPriority.Normal ' Instantiate a new instance of SmtpClient Dim mSmtpClient As New SmtpClient() mSmtpClient.Host = "------" mSmtpClient.Port = "---------" mSmtpClient.Credentials = New System.Net.NetworkCredential("-----------", "----------") ' Send the mail message mSmtpClient.Send(mMailMessage) End Sub
End Class Use this class
regards Rajeesh MP
-
In Gridview CaseNo ,HearingDate,To,CC,BCC this data is shown. CaseNo is Primary Key I am having button "SendMail" in that grid view. In gridview Rowcommand Event i write this code if i click on first row send mail command button then Label9.text get First caseno t.e. "LER/111" Simillarly i want To,CC BCC Cell value of that row How i can able to get that
Protected Sub MailDetailsGridView_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles MailDetailsGridView.RowCommand ''Code Added For The Send Mail........ If (e.CommandName = "SendMail") Then Label9.Text = e.CommandArgument.ToString() Dim row As GridViewRow row = CType(CType(e.CommandSource, Control).NamingContainer, GridViewRow) Dim email As String = CType(row.Cells(6), DataControlFieldCell).Text If (row.RowType = DataControlRowType.DataRow) Then Dim txtCCMail As TextBox Dim ToMail As String txtCCMail = row.Cells(6).Controls(0).FindControl("ToTextBox") ToMail = txtCCMail.Text End If End If End Sub
txtCCMail = row.Cells(7).Controls(0).FindControl("ccTextBox") txtBCCMail = row.Cells(9).Controls(0).FindControl("bccTextBox")