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



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@xxxxxxxxxxxxxxxx>
wrote in message news:uYbZ6kikHHA.4248@xxxxxxxxxxxxxxxxxxxxxxx
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
-----------------------------------------




.



Relevant Pages

  • RE: GridViewRow.DataItem is null
    ... BTW, currently, you'll dynamically create Gridview and DataSource control ... Usercontrol into page, you can dynamically load the usercontrol and add ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: ObjectDataSource in ASP.NET 2.0
    ... > property so as to make the primary key field readonly or invisible. ... > event we define the following gridView template schema: ... > update event of the GridView or DataSource control. ... > |> Microsoft Online Support ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: How to modify SqlDataAdapter field prior to render in GridView
    ... Method #2 worked real well for the GridView control. ... We can also do the manipulation at databound control level. ... How to modify SqlDataAdapter field prior to render in GridView? ...
    (microsoft.public.dotnet.framework.adonet)
  • RE: GridView UserControl Problems
    ... If the final GridView structure is decided upon based on the data that is ... I have designed a UserControl for each different type of input. ... the DropDownList control. ... In the main page, I use the GridView's RowDataBound event, (fired once ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: GridViewRow FindControl failing
    ... You can definitely do this from some of the gridview events such as ... GridViewRow selectRow = MyGridView.SelectedRow; ... it resides as a direct child of the control you are finding from. ... Dim sManagerTypeCode = r.Cells.Text ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)

Loading