G
Guest
I have a web form that contains a Datagrid that contains all rows from the
Categories table in the Northwind database. I have written code that dumps
all categoryID's from the Category table to a DataList. Once the user
selects a choice from the List, the DataGrid is re-populated with only the
row that the user selected. The row appears with Update and Delete buttons.
When a user clicks delete, a stored procedure runs and deletes the record. I
want the DataGRid to be refreshed with the full table minus the deleted row,
but I can't get it to work. My code for the delete is as follows:
Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DataGrid1.DeleteCommand
SqlConnection1.Open()
Try
Dim command As SqlCommand = New SqlCommand("DeleteCategory",
SqlConnection1)
command.CommandType = CommandType.StoredProcedure
command.Parameters.Add("@CategoryID", ddlCategoryID.SelectedItem.Text)
Console.WriteLine("Rows Deleted: " + _
command.ExecuteNonQuery().ToString())
Catch ex As Exception
Console.WriteLine(ex.Message)
Throw
Finally
DataGrid1.DataSource = DsCategories11()
DataGrid1.DataBind()
End Try
End Sub
Categories table in the Northwind database. I have written code that dumps
all categoryID's from the Category table to a DataList. Once the user
selects a choice from the List, the DataGrid is re-populated with only the
row that the user selected. The row appears with Update and Delete buttons.
When a user clicks delete, a stored procedure runs and deletes the record. I
want the DataGRid to be refreshed with the full table minus the deleted row,
but I can't get it to work. My code for the delete is as follows:
Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DataGrid1.DeleteCommand
SqlConnection1.Open()
Try
Dim command As SqlCommand = New SqlCommand("DeleteCategory",
SqlConnection1)
command.CommandType = CommandType.StoredProcedure
command.Parameters.Add("@CategoryID", ddlCategoryID.SelectedItem.Text)
Console.WriteLine("Rows Deleted: " + _
command.ExecuteNonQuery().ToString())
Catch ex As Exception
Console.WriteLine(ex.Message)
Throw
Finally
DataGrid1.DataSource = DsCategories11()
DataGrid1.DataBind()
End Try
End Sub