Groups | Blog | Home
all groups > asp.net datagrid control > may 2007 >

asp.net datagrid control : Strange Problem: Removing rows from Table object doesnt update rowcount of Gridview


Dev
5/5/2007 12:00:00 AM
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
5/6/2007 12:00:00 AM
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


[quoted text, click to view]

Dev
5/7/2007 12:00:00 AM
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" <REMOVEALLCAPITALSeEgGoldDinN@mMvVpPsS.org> wrote in
message news:eOS1J87jHHA.4040@TK2MSFTNGP03.phx.gbl...
[quoted text, click to view]

MasterGaurav (www.edujini-labs.com)
5/9/2007 1:05:37 PM
[quoted text, click to view]

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
5/9/2007 5:50:42 PM
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)" <gaurav.vaish.nospam@nospam.gmail.com>
[quoted text, click to view]

MasterGaurav (www.edujini-labs.com)
5/31/2007 5:31:56 PM
[quoted text, click to view]

You may bind the datagrid to DataView with a "Filter" with appropriate
"SortColumn".

DataView will not modify the underlying table but at the same time will be
able to "Filter" the data to be given to the grid.


--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujini-labs.com
-----------------------------------------

AddThis Social Bookmark Button