|
-
Feb 24th, 2004, 09:57 AM
#1
Thread Starter
Member
multiple delete
Hi,
i have try to use multiple checkbox to delete users by using datagrid.
Below is my codes:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim conn As OleDbConnection
Dim objCmd = New OleDbCommand
conn = connectToDB()
objCmd.commandtext = "spGetMembers"
objCmd.CommandType = CommandType.StoredProcedure
objCmd.connection = conn
Dim myDataReader As OleDbDataReader
myDataReader = objCmd.ExecuteReader
dgDelMember.DataSource = myDataReader
dgDelMember.DataBind()
conn.close()
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
Dim Item
For Each Item In Request.QueryString("chkMemDelete")
'SQL statement here
Dim conn As OleDbConnection
Dim objCmd = New OleDbCommand
conn = connectToDB()
objCmd.commandtext = "spDelMembers"
objCmd.CommandType = CommandType.StoredProcedure
objCmd.connection = conn
Dim myDataReader As OleDbDataReader
myDataReader = objCmd.ExecuteReader
dgDelMember.DataSource = myDataReader
dgDelMember.DataBind()
conn.Close()
Next
End Sub
But they can't find the "chkMemDelete" as the id for checkbox is in the datagrid.
Error:
Object reference not set to an instance of an object.
-
Feb 24th, 2004, 11:33 AM
#2
PowerPoster
First off, your going about this the wrong way. You are still thinkin in terms of Classic ASP. Simply iterate through the datagrid's Items's collection and do a findcontrol on the checkbox name and from there, determine which items to delete.
-
Feb 24th, 2004, 09:21 PM
#3
Thread Starter
Member
Thank You Lethal.
Now i'm trying the other way which you told me... it does not have error but does not delete the users. Can point me my where is my mistake? Thankz...
here is my coding:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim conn As OleDbConnection
Dim objCmd = New OleDbCommand
conn = connectToDB()
objCmd.commandtext = "spGetMembers"
objCmd.CommandType = CommandType.StoredProcedure
objCmd.connection = conn
Dim myDataReader As OleDbDataReader
myDataReader = objCmd.ExecuteReader
dgDelMember.DataSource = myDataReader
dgDelMember.DataBind()
conn.close()
End Sub
Private Sub dgDelMember_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgDelMember.ItemCommand
If CType(e.Item.FindControl("chkMemDelete"), CheckBox).Checked And e.CommandName = "DeleteButton" Then
Dim conn As OleDbConnection
Dim objCmd = New OleDbCommand
conn = connectToDB()
objCmd.commandtext = "spDelMembers"
objCmd.CommandType = CommandType.StoredProcedure
objCmd.connection = conn
Dim myDataReader As OleDbDataReader
myDataReader = objCmd.ExecuteReader
dgDelMember.DataSource = myDataReader
dgDelMember.DataBind()
conn.Close()
End If
End Sub
End Class
-
Feb 25th, 2004, 06:22 AM
#4
Thread Starter
Member
Do i have to use the dataset? I do not know how to tell the system that these are the ID that need to be deleted.
Private Sub dgDelMember_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgDelMember.ItemCommand
Dim dgItem As DataGridItem
Dim result As String
For Each dgItem In dgDelMember.Items
If CType(dgItem.FindControl("chkMemDelete"), CheckBox).Checked And e.CommandName = "DeleteButton" Then
Dim conn As OleDbConnection
Dim objCmd As New OleDbCommand
Session("Chk_CustID") = CType(dgItem.FindControl("chkMemDelete"), CheckBox).Text
conn = connectToDB()
objCmd.CommandText = "spDelMembers"
objCmd.CommandType = CommandType.StoredProcedure
objCmd.Connection = conn
''codes for assigning parameters
Dim objparam As OleDbParameter
objparam = objCmd.Parameters.Add("RETURN_VALUE", SqlDbType.Int)
objparam.Direction = ParameterDirection.ReturnValue
objCmd.Parameters.Add("@CustID", Session("Chk_CustID"))
' Execute SQL and read data from database
objCmd.ExecuteNonQuery()
' Bind the records to the data list control
dgDelMember.DataBind()
' Close the connection object
conn.Close()
End If
Next
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|