K
katmagic
I have an editable gridview on a page, when I delete a record, the gridview
still reflects the old dataset. The record is successfully deleted, I
connect to the database, get a new dataset, and bind it to the grid, and it
still reflects the old one with the deleted record. I've tried setting the
datasource to nothing, then rebinding, I have tried to set the datasource to
be equal to an empty table, then bind the grid. So it's the display that is
the problem, the display does not refresh. If I refresh the page via
redirecting to itself, that works but then everything else on the page is
affected and I don't want that.
So how do I get the gridview to display the correct datasource? This is my
code I use to empty the gridview when the record is deleted:
Protected Sub gvContactDetails_RowCommand(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.GridViewCommandEventArgs)
Dim businesslayer As New BusinessLayerClass
Dim connString as String = myconnectionstring
Dim ID as String = ""
Dim retval as Integer = 0
if e.CommandName = "Delete"
ID = e.CommandArgument.ToString
retval = bl.OrderItemDelete(connString, id)
If retVal = 0
ErrorMessage.Text = "Item cannot be deleted."
else
dim dt As new DataTable
GridviewOrderDetailsSection1.DataSource = dt
GridviewOrderDetailsSection1.DataBind
end if
end if
End Sub
still reflects the old dataset. The record is successfully deleted, I
connect to the database, get a new dataset, and bind it to the grid, and it
still reflects the old one with the deleted record. I've tried setting the
datasource to nothing, then rebinding, I have tried to set the datasource to
be equal to an empty table, then bind the grid. So it's the display that is
the problem, the display does not refresh. If I refresh the page via
redirecting to itself, that works but then everything else on the page is
affected and I don't want that.
So how do I get the gridview to display the correct datasource? This is my
code I use to empty the gridview when the record is deleted:
Protected Sub gvContactDetails_RowCommand(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.GridViewCommandEventArgs)
Dim businesslayer As New BusinessLayerClass
Dim connString as String = myconnectionstring
Dim ID as String = ""
Dim retval as Integer = 0
if e.CommandName = "Delete"
ID = e.CommandArgument.ToString
retval = bl.OrderItemDelete(connString, id)
If retVal = 0
ErrorMessage.Text = "Item cannot be deleted."
else
dim dt As new DataTable
GridviewOrderDetailsSection1.DataSource = dt
GridviewOrderDetailsSection1.DataBind
end if
end if
End Sub