Gridview datsetitemindex incorrect after delete/databind RRS feed

  • Question

  • I have a web application that loads a data and edits data detached from the data source. This information is presented to the user via a gridview. The user may do all kinds of crud to the data before it is all presented back via the save button. Everything works just danady except for the condition when the user deletes a record and then edits another records later in the sequence. In this scenario the user presses the "delete" link button within the grid and the record (say e.rowindex  2) disappears as expected. Then the user "edits" the next record (now displaying as e.rowindex 2 but was previously in position 3). The edit displays as expected and the user can enter their changes.

    When the user clicks "Update" it all falls apart. In this scenario a DeletedRowInaccessible exception is genreated. If the edited record is lower in the list the one above it is overwriiten. I confirmed the issue was due to the RowDataItemIndex referencing and incorrect row. I obtain the Row data item by
         GridViewRow row = GridView1.Rows[e.RowIndex];
    Again this works for all other cases. Apparently the rules for painting and displaying the grid at databind are to ignore the deleted record. This works fine for the Grid and the RowIndex but really shouldn't apply to the DataItemIndex used in the event handler..

    Fyi Using Removeat() made the error go away, but of course the loader.update wouldn't work with the record gone. I was able to resolve the issue by running all the changes and deletes through defaultview and setting a rowstate filter to CurrentRows. This removed the deleted record from the filtered records so that both the grid and the event would see the data the same.

    Fuund the solution while I was collecting background for the question and decided to post this for reference.

    Friday, February 12, 2010 10:19 PM

All replies

  • Try FastSQLDataSource. It helps when you need faster display of large amounts of SQL Server data in your web application using grids, lists and other bound controls.

    It supports automatic paging and sorting and performs very quickly on large amounts of data

    It can work almost without coding or sometimes with no coding at all.

    Monday, February 15, 2010 8:39 PM
  • Rockindad -- Your post has absolutely nothing to do with the OP's question and basically amounts to advertising. At least that's what it sounds like to me. Try to stay on topic next time.
    ~~Bonnie Berent [C# MVP]
    Tuesday, February 16, 2010 9:02 PM