Refreshing a gridview problem


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
 
Ad

Advertisements

N

nathansneely

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

If I understand your question correctly, what you're trying to do is
update one control on the page without refreshing the whole page. You
should be using the AJAX controls to accomplish that.

Hope that helps,

Nathan Neely
(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