Refresh a DataGrid

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
 
E

Elton Wang

Hi Tom,

What trouble do you have and what code is in DsCategories11
()?

Elton Wang
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top