Blog Just another tech site

15Sep/121 Update grid view after updating a linked form view

Grid View linked to Form View

A personal project I am currently working on is creating a database site, which will drive a organizations on-line membership management system.

One of the pages relies on a grid view at the top, which has selectable rows which a form view below relies on. The form view has a data key name of the selected row in the grid view.

When a row / field is updated in the form view, this is not instantly shown in the grid view, but instead will show after a page reload. I first presumed that auto post back would update the grid view, but as it is not the data view that is updated, the system does not automatically update it.

One way I have found to get around this pain, is to create a custom method which rebinds the data source to the grid view after the form view has been updated.

Under the formview object on the aspx page add the following (change the method name as required):


Adding on item updated method

The related method in the backend code then needs to be created, add the following code:

protected void FormView1_ItemUpdated(object sender, EventArgs e)

Since this is being called after the item has been updated, the datasource will have already been updated, therefore the new data simply needs to be pushed / bound to the grid view object.

Adding the required back-end code

After these changes my grid view now updates instantly without the need to refresh the page.

Filed under: Asp.Net, Software 1 Comment