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

D

Dev

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
 
D

Dev

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 said:
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 said:
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
 
D

Dev

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
 

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

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top