C
Chumley the Walrus
IN my code behind .vb page for a delete records script (this also does
a deletion confirmation with a javascript popup, this gets called on
my front .aspx page with the datagrid), I'm not sure if he
row.delete() in my Delete_Row sub is correct because when deleting a
record from the dbase, it doesnot get deleted from the actual
database, even tho on the datagrid it does show that the record is
deleted:
'''''''''''''
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Web.UI.WebControls
Public Class ConfirmDelDG
Inherits System.Web.UI.Page
Protected WithEvents dtgProducts As
System.Web.UI.WebControls.DataGrid
Private strConnection As String =
"SERVER=xxxx.xxx.xxx.xx;UID=xxxx;PWD=xxxx;DATABASE=players;"
Private strSql As String = "SELECT * FROM pictures Order by pid
desc"
Private objConn As SqlConnection
Private Sub Page_Load(ByVal Sender As System.Object, ByVal E As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
BindTheGrid()
End If
End Sub
Private Sub BindTheGrid()
Connect()
Dim adapter As New SqlDataAdapter(strSql, objConn)
Dim ds As New DataSet()
adapter.Fill(ds, "pictures")
Disconnect()
dtgProducts.DataSource = ds.Tables("pictures")
dtgProducts.DataBind()
End Sub
Private Sub Connect()
If objConn Is Nothing Then
objConn = New SqlConnection(strConnection)
End If
If objConn.State = ConnectionState.Closed Then
objConn.Open()
End If
End Sub
Private Sub Disconnect()
objConn.Dispose()
End Sub
Private Sub dtgProducts_ItemDataBound (ByVal sender As
System.Object, _
ByVal e As DataGridItemEventArgs) Handles
dtgProducts.ItemDataBound
Dim btn As Button
If e.Item.ItemType = ListItemType.Item or e.Item.ItemType =
ListItemType.AlternatingItem Then
btn = CType(e.Item.Cells(0).FindControl("btnDelete"), Button)
btn.Attributes.Add("onclick", "return confirm_delete();")
End If
End Sub
Public Sub Delete_Row(ByVal Sender As Object, ByVal E As
DataGridCommandEventArgs)
' Retrieve the ID of the product to be deleted
Dim pid As system.Int32 =
System.Convert.ToInt32(E.Item.Cells(0).Text)
dtgProducts.EditItemIndex = -1
' Create and load a DataSet
Connect()
Dim adapter As New SqlDataAdapter(strSql, objConn)
Dim ds As New DataSet()
adapter.Fill(ds, "pictures")
Disconnect()
' Mark the product as Deleted in the DataSet
Dim tbl As DataTable = ds.Tables("pictures")
tbl.PrimaryKey = New DataColumn() _
{ _
tbl.Columns("pid") _
}
Dim row As DataRow = tbl.Rows.Find(pid)
row.Delete()
' Display remaining rows in the DataGrid
dtgProducts.DataSource = ds.Tables("pictures")
dtgProducts.DataBind()
End Sub
End Class
''''''''''''
??????
chumley
a deletion confirmation with a javascript popup, this gets called on
my front .aspx page with the datagrid), I'm not sure if he
row.delete() in my Delete_Row sub is correct because when deleting a
record from the dbase, it doesnot get deleted from the actual
database, even tho on the datagrid it does show that the record is
deleted:
'''''''''''''
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Web.UI.WebControls
Public Class ConfirmDelDG
Inherits System.Web.UI.Page
Protected WithEvents dtgProducts As
System.Web.UI.WebControls.DataGrid
Private strConnection As String =
"SERVER=xxxx.xxx.xxx.xx;UID=xxxx;PWD=xxxx;DATABASE=players;"
Private strSql As String = "SELECT * FROM pictures Order by pid
desc"
Private objConn As SqlConnection
Private Sub Page_Load(ByVal Sender As System.Object, ByVal E As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
BindTheGrid()
End If
End Sub
Private Sub BindTheGrid()
Connect()
Dim adapter As New SqlDataAdapter(strSql, objConn)
Dim ds As New DataSet()
adapter.Fill(ds, "pictures")
Disconnect()
dtgProducts.DataSource = ds.Tables("pictures")
dtgProducts.DataBind()
End Sub
Private Sub Connect()
If objConn Is Nothing Then
objConn = New SqlConnection(strConnection)
End If
If objConn.State = ConnectionState.Closed Then
objConn.Open()
End If
End Sub
Private Sub Disconnect()
objConn.Dispose()
End Sub
Private Sub dtgProducts_ItemDataBound (ByVal sender As
System.Object, _
ByVal e As DataGridItemEventArgs) Handles
dtgProducts.ItemDataBound
Dim btn As Button
If e.Item.ItemType = ListItemType.Item or e.Item.ItemType =
ListItemType.AlternatingItem Then
btn = CType(e.Item.Cells(0).FindControl("btnDelete"), Button)
btn.Attributes.Add("onclick", "return confirm_delete();")
End If
End Sub
Public Sub Delete_Row(ByVal Sender As Object, ByVal E As
DataGridCommandEventArgs)
' Retrieve the ID of the product to be deleted
Dim pid As system.Int32 =
System.Convert.ToInt32(E.Item.Cells(0).Text)
dtgProducts.EditItemIndex = -1
' Create and load a DataSet
Connect()
Dim adapter As New SqlDataAdapter(strSql, objConn)
Dim ds As New DataSet()
adapter.Fill(ds, "pictures")
Disconnect()
' Mark the product as Deleted in the DataSet
Dim tbl As DataTable = ds.Tables("pictures")
tbl.PrimaryKey = New DataColumn() _
{ _
tbl.Columns("pid") _
}
Dim row As DataRow = tbl.Rows.Find(pid)
row.Delete()
' Display remaining rows in the DataGrid
dtgProducts.DataSource = ds.Tables("pictures")
dtgProducts.DataBind()
End Sub
End Class
''''''''''''
??????
chumley