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

    Hi,

    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
    Dev, May 5, 2007
    #1
    1. Advertising

  2. What is Table.Remove()? What class is Table? How is it related to the grid?

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Dev" <> wrote in message
    news:...
    > Hi,
    >
    > 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
    >
    Eliyahu Goldin, May 6, 2007
    #2
    1. Advertising

  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

    "Eliyahu Goldin" <> wrote in
    message news:...
    > What is Table.Remove()? What class is Table? How is it related to the
    > grid?
    >
    > --
    > Eliyahu Goldin,
    > Software Developer & Consultant
    > Microsoft MVP [ASP.NET]
    > http://msmvps.com/blogs/egoldin
    > http://usableasp.net
    >
    >
    > "Dev" <> wrote in message
    > news:...
    >> Hi,
    >>
    >> 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
    >>

    >
    >
    Dev, May 7, 2007
    #3
  4. Dev

    Dev Guest

    Hi Gaurav,

    Thanks. I'm trying to do this in ASP.net 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

    "MasterGaurav (www.edujini-labs.com)" <>
    wrote in message news:...
    >> 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?

    >
    > That's not the way of removing rows.
    > Gridview.Rows.Count does not return Table.Rows.Count!
    >
    > Gridview.Rows.Count is for the DataSource's row-count.
    > Well, you cannot control the items that will be pushed in the grid if you
    > cannot control the data-source.
    >
    > If you want to remove any item, ensure that you also remove it from the
    > datasource to which you are binding the gridview.
    >
    >
    > --
    > Happy Hacking,
    > Gaurav Vaish | www.mastergaurav.com
    > www.edujini-labs.com
    > http://eduzine.edujini-labs.com
    > -----------------------------------------
    >
    >
    Dev, May 9, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mesut
    Replies:
    0
    Views:
    652
    mesut
    Feb 19, 2007
  2. sanju
    Replies:
    0
    Views:
    475
    sanju
    Aug 28, 2007
  3. Replies:
    3
    Views:
    425
    alex23
    May 27, 2008
  4. FLORAL

    Using @@rowcount after update in ASP

    FLORAL, Feb 5, 2004, in forum: ASP General
    Replies:
    1
    Views:
    121
    Bob Barrows
    Feb 5, 2004
  5. HoustonLucifer

    Rowcount of a table

    HoustonLucifer, Jun 30, 2004, in forum: ASP General
    Replies:
    3
    Views:
    138
    Aaron [SQL Server MVP]
    Jul 1, 2004
Loading...

Share This Page