"Requery" a datagrid based on changes in underlying dataset
Posted on 2006-03-28
I have a datagrid (DataGrid1) on a webform. The datagrid is "bound" to the dataset dsJobs1. DsJobs1 is derived from OleDBAdapter1. The datasource of OleDBAdapter1 is:
SELECT JobID, JobTitle, JobDesc
The connection is to a single table in a Microsoft Access Database on the server.
In the property builder of the datagrid, I am displaying the "Delete" column, and the control appears as a pushbutton. When the "Delete" button is pushed, I don't really want it to delete the row from the database; I want it to change the value of JobFilled to -1, and redisplay the datagrid (This is an oversimplification; I'm doing other stuff, too, but for these purposes, I'll just use this as the example). Since JobFilled is no longer 0, the row that I just "deleted" shouldn't be there.
So far, I have the following code:
Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand
Dim intIndex = e.Item.ItemIndex
Dim ds As DataSet
Dim tbl As DataTable
ds = Me.DsJobs1
tbl = ds.Tables("Jobs")
.Item("JobFilled") = -1
Me.DataGrid1.EditItemIndex = -1
Besides some possibly redundant coding (do I really need to databind the datagrid twice at the end of the sub?)...this is not giving me the results I'm hoping for. The datagrid still shows the "Deleted" row. If I exit the form, and open it back up again, it's gone, but I want it to update immediately.