Last post Sep 17, 2010 02:28 PM by atconway
Aug 19, 2010 12:12 PM|th3funnyman|LINK
I have the following method to strip hidden and user-specified columns from a gridviewrow and return a tablerow.
Private Shared Function StripHiddenColumns(ByVal gvRow As GridViewRow, ByVal ColumnsToExclude() As Integer) As TableRow
Dim row As New TableRow
Dim i As Integer = 0
For Each cell As TableCell In gvRow.Cells
If cell.Visible Then
If Not ColumnsToExclude.Contains(i) Then
i += 1
Catch ex As Exception
However, when I run this code and hit the Add method for the TableRow, I get an InvalidOperationException stating the Collection was modified; enumeration operation may not execute. I've gotten this exception before, but usually it's because I'm attempting
to modify a table that is databound. This particular one is not, i am creating it. Can anyone offer any insight?
Thanks in advance.
Aug 19, 2010 12:22 PM|ketan_al|LINK
Please refer following
hope this helps
Aug 19, 2010 01:46 PM|th3funnyman|LINK
Thanks for your reply and the links. I read through them all and none really seem to fit my situation. The problems at the target links were because the dev was attempting to directly modify the collection he/she was looping through while in the loop.
I understand that this is a common error, and I have experienced it before, but it was while I was trying to modify a collection that was already built. I am just trying to build a table row and add cells from a gridview to it. Am I not allowed to build
a tablerow object by adding cells to it?
I did notice that when I add the gridview cell to the table row, the gridview's cell count property decrements by one. I do not understand why this is happening. There is not one line of code in my original post that removes a cell from the gridview.
I'm obviously doing something wrong. Could someone show me an alternate way of converting a gridview row into a tablerow while excluding cells that aren't set as "visible" and also while excluding a given array of column indexes?
Sep 17, 2010 02:28 PM|atconway|LINK
You really have (3) options here:
I really think you should eliminate records before binding not after
as I presented in option #1. It is the easiest and you will bypass issues trying to modify the .Cells collection on the GridView.
Hope this helps!