InBox.aspx.vb

Imports System.Data

Imports System.IO

Imports System.Drawing

Imports System.Data.SqlClient

 

 

Public Class MyMessages

 

    Inherits System.Web.UI.Page

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        If Not IsPostBack Then

            Dim msg

            msg = Request.QueryString("msg")

            If msg <> Trim("") Then

                lblDeleted.Text = "Message Successfully Deleted"

            End If

 

 

         btnDeleteAll.Attributes.Add("onclick", "JavaScript:return confirm('Are you sure you want to delete?');")

 

            Dim myConnection As SqlConnection

            Dim myCommand As SqlCommand

            Dim myDataTable As New DataTable

            Dim myRow As DataRow

           

 

            myConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("Your Connection String"))

            myCommand = New SqlCommand("Your Stored Procedure", myConnection)

            myCommand.CommandType = CommandType.StoredProcedure

            myConnection.Open()

            Dim myDataReader As SqlDataReader = myCommand.ExecuteReader()

 

            myDataTable.Columns.Add("Select", System.Type.GetType("System.String"))

            myDataTable.Columns.Add("From", System.Type.GetType("System.String"))

            myDataTable.Columns.Add("Subject", System.Type.GetType("System.String"))

            myDataTable.Columns.Add("Date", System.Type.GetType("System.String"))

 

            If myDataReader.HasRows = True Then

                While myDataReader.Read()

                    myRow = myDataTable.NewRow()

                    If myDataReader("chStatus") = "N" Then

                        myRow("Select") = "<input type=""checkbox"" name=""checkbox"" id=""checkbox"" value =" & myDataReader("intID") & " />"

                        myRow("From") = myDataReader("intFromID")

                        myRow("Subject") = myDataReader("chSubject")

                        myRow("Date") = myDataReader("dteMsgDate")

                    Else

                        myRow("Select") = "<input type=""checkbox"" name=""checkbox"" id=""checkbox"" value =" & myDataReader("intID") & " />"

                        myRow("From") = myDataReader("vchFromName")

                        myRow("Subject") = myDataReader("chSubject")

                        myRow("Date") = myDataReader("dteMsgDate")

                    End If

                    myDataTable.Rows.Add(myRow)

                    btnDeleteAll.Visible = True

                    lblSelectall.Text = "<a href=""javascript:SetChecked(1,'checkbox')"">Select All</a>"

                    lblUnselectAll.Text = "<a href=""javascript:SetChecked(0,'checkbox')"">Clear All</a>"

                End While

 

                MyInboxGrid.DataSource = myDataTable.DefaultView

 

                MyInboxGrid.DataBind()

            Else

                myRow = myDataTable.NewRow()

                myRow("Select") = "<input type=""checkbox"" name=""checkbox"" id=""checkbox"" />"

                myRow("From") = ""

                myRow("Subject") = ""

                myRow("Date") = ""

                lblNoMessage.Text = "There is no entry in the database"

                myDataTable.Rows.Add(myRow)

                MyInboxGrid.DataSource = myDataTable.DefaultView

                MyInboxGrid.DataBind()

            End If

            myConnection.Close()

 

        End If

 

    End Sub

 

 

    Public Sub MassDelete(ByVal sender As System.Object, ByVal e As System.EventArgs)

        Dim strDeleteList

        strDeleteList = Request("checkbox")

        Dim myConnection As New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("YourConnection String"))

        Dim myCommand As New SqlCommand( _

                           "DELETE FROM YourTable WHERE intID  IN (" + Replace(strDeleteList, "'", "''") + ")", _

                            myConnection)

 

        myCommand.Connection.Open()

        myCommand.ExecuteNonQuery()

        myCommand.Connection.Close()

        Response.Redirect("Inbox.aspx")

    End Sub

 

End Class