Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 24th, 2007, 12:32 AM
Authorized User
 
Join Date: Aug 2007
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to yukijocelyn
Default Checkbox in Gridview

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("xxx@somewhere.com")
        mailObj.To.Add(New MailAddress("yyy@someone.com"))
        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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Gridview and Checkbox krasnokojiy ASP.NET 2.0 Basics 14 February 28th, 2008 12:56 PM
Confirmation with checkbox in gridview collie Visual Studio 2005 0 October 24th, 2007 06:13 AM
GridView Checkbox ItemTemplate angelicagm ASP.NET 2.0 Professional 3 May 31st, 2007 04:44 AM
Checkbox in GridView aliirfan84 ASP.NET 2.0 Professional 1 May 15th, 2007 03:59 PM
Gridview checkbox problems pauliehaha ASP.NET 2.0 Professional 1 May 3rd, 2007 04:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.