Strange Problem: Removing rows from Table object doesnt update rowcount of Gridview

Discussion in 'ASP .Net Datagrid Control' started by Dev, May 5, 2007.

  1. Dev

    Dev Guest


    I'm removing rows from a gridview using Table.Remove( ). This removes the
    rows from the gridview.
    But the problem is although it removes rows from the gridview it doesnt
    update the Gridview.Rows.Count to return correct number of rows remains on
    the gridview. Instead it always returns the number of rows gridview
    originally had prior to removing them.

    Anybody know why this is happening? How to remove gridview rows in a manner
    so that it will update the rows.count property correctly?

    Note: I'm looking for a method to directly remove rows from a gridview
    without having to rebinding gridview to datasource controls etc...

    Dev, May 5, 2007
    1. Advertisements

  2. Eliyahu Goldin, May 6, 2007
    1. Advertisements

  3. Dev

    Dev Guest

    Hi Goldin,

    Just check the object returned by Gridview.controls(0). This is a Childtable
    which you can typecast to Table.
    Using this you can add new rows, delete rows (as I've mentioned) in a
    gridview directly. Let me know if u figure out how to overcome the problem
    I've mentioned below.


    Dev, May 7, 2007
  4. Dev

    Dev Guest

    Hi Gaurav,

    Thanks. I'm trying to do this in and gridview is bount to a
    datatable. I dont need to use a datasource control in this case as I'm not
    trying to delete any rows from the database.

    How to remove rows from the source datatable on postback?

    Do I have to access database on postback, recreate the datatable without the
    rows I want to get rid off and bind the datatable to the gridview is it? If
    so it doesnt sound a good method for me as I dont want to access the
    database unnecessarily.

    Any ideas?

    Dev, May 9, 2007
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.