Hi
I have another function I want here in my application.
I would like to add the checkbox functionality into my gridview control where I allow my users to be able to select those records that they want, then the check boxes' rows' data will be emailed to them. How can I make this checkboxes selection work?
Below are the current codes that I have, how can I integrate them to use the selected data?
Thank you!
This allos the gridview to display all the combination of the data
Protected Sub lblFind_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim selectedDate As DateTime
Dim selectedCompany As String
selectedDate = ddlDateCreated.SelectedValue
selectedCompany = ddlCompany.SelectedValue.ToString
Dim dbconn As OleDbConnection
Dim sql As String
Dim dbcomm As OleDbCommand
Dim dataAdap As OleDbDataAdapter
Dim ds As DataSet
Dim dr As OleDbDataReader
dbconn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=" & Server.MapPath("App_Data/DB.mdb"))
dbconn.Open()
sql = "SELECT ID, acct, number, FullName FROM table WHERE o LIKE '" + selectedCompany + "%'" + " and DateCreated LIKE '" + selectedDate + "%'"
dbcomm = New OleDbCommand(sql, dbconn)
dataAdap = New OleDbDataAdapter(dbcomm)
ds = New DataSet
Try
lblEmailTo.Visible = True
ddlEmailTo.Visible = True
cmdSendEmail.Visible = True
dataAdap.Fill(ds)
GridView1.DataSource = ds
GridView1.DataBind()
Catch ex As Exception
lblEmailTo.Visible = False
ddlEmailTo.Visible = False
cmdSendEmail.Visible = False
MsgBox("No records found for " + selectedCompany + " and of date " + selectedDate, MsgBoxStyle.OkOnly, "No Records Found")
End Try
End Sub
The sends the email to the reicipient
Protected Sub Button1_Click1(ByVal sender As Object, ByVal e As System.EventArgs)
Dim dbconn As OleDbConnection
Dim cmd As OleDbCommand
Dim sql As String
Dim rd As OleDbDataReader
'Prepare the data to send to the receipients
Dim greetings As String = "Hi there detail as shown."
Dim tblheading As String = "<table border=1><tr align=center><td><b>ID</b></td><td><b>Account</b></td><td><b>Number</b></td><td><b>Full Name</b></td></tr>"
Dim contents As String = " "
Dim tblending As String = "</table>"
Dim signoff As String = "<p>Rgds"
à à Ã
Dim selectedDate As DateTime = ddlDateCreated.SelectedValue
Dim selectedCompany As String = ddlCompany.SelectedValue.ToString
dbconn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=" & Server.MapPath("App_Data/DB.mdb"))
dbconn.Open()
sql = "SELECT ID, acct, number, FullName FROM table WHERE o LIKE '" + selectedCompany + "%'" + " and DateCreated LIKE '" + selectedDate + "%'"
cmd = New OleDbCommand(sql, dbconn)
rd = cmd.ExecuteReader
While rd.Read
contents = contents + "<tr align=center>"
contents = contents + "<td>"
contents = contents + rd("ID").ToString
contents = contents + "</td><td>"
contents = contents + rd("acct")
contents = contents + "</td><td>"
contents = contents + rd("number")
contents = contents + "</td><td>"
contents = contents + rd("FullName")
contents = contents + "</td></tr>"
End While
MsgBox(contents)
MsgBox(greetings + tblheading + contents + tblending + signoff)
Dim mailObj As New MailMessage
mailObj.From = New MailAddress("
[email protected]")
mailObj.To.Add(New MailAddress("
[email protected]"))
mailObj.Subject = "Testing of Email"
mailObj.Body = greetings + tblheading + contents + tblending + signoff
mailObj.IsBodyHtml = True
Dim client As New SmtpClient
client.Send(mailObj)
rd.Close()
dbconn.Close()
End Sub