开发者

foreach row in grid

I have a grid with 100 pages and 10 items per page.(The size of the grid is dynamic) I have a delete command. Everything works fine. Now I need to add recursive delete command which is gonig to remove ALL rows from the grid.

I'm trying to do this:

foreach (GridDataItem item in RadGrid1.Items)
{

}

but it only counts rows on a single page (Remove 10 records at a time)

How can I run he same thing for each row in the whole grid?

gv.Items.count also giv开发者_C百科es 10


I'm assuming this is for the RadGrid for ASP.NET AJAX, but feel free to correct me if I'm wrong.

The RadGrid will only contain the items that is is currently displaying. So if you have a page size of 10 it will only contain 10 items in the RadGrid.Items collection.

If you want to get access to all the items of the RadGrid the best is really go to back to the original datasource. So if this is a DataSet I wold just use some server-side logic to remove the items from that data and then call .Rebind() to the RadGrid, which will update the Grid to display the current items.

However, if going to the original datasource isn't an option you could always set AllowPaging to false (on the MasterTableView of the RadGrid), call .Rebind(), do all of your logic (RadGrid.Items will now have all of your items) then set AllowPaging to true and call .Rebind() again. This is a bit more inefficient though, but could very well work.

What makes the most sense is to go back to the underlying data though. If you're trying to remove all of the data from the RadGrid why don't you just set the datasource to an empty array and call .Databind() or .Rebind()? Much faster than deleting all of the items from the RadGrid one at a time.


Solution suggested by carlbergenhem make sense. But, if you are looking to wipe out data from database, you can simply delete it by running SQL DELETE command and then rebind your Grid.

DELETE FROM <<YOUR TABLE NAME>> WHERE <<CONDITION>>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜