This is a migrated thread and some comments may be shown as answers.

Populated Array List from Grid

7 Answers 187 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 04 Aug 2008, 02:10 PM
I am trying to populate an arraylist from the list of items in the gridview.

Here is the code I am using to do this in the RadGrid_ItemDataBound Sub.

  If (TypeOf (e.Item) Is GridDataItem) Then
            If DocumentList Is Nothing Then
                DocumentList = New ArrayList
            End If

            DocumentList.Add(e.Item.DataItem(0))
        End If

This should work, but it populates the arraylist with the data twice.  Not sure what is going on here and any help would be appreciated. 

One example would be this.  If the DocumentID is 8.  Then it will add 8 twice to the array list instead of once.  This even occurs if you put If not ispostaback around the if statement.

Thanks in advance.

7 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 04 Aug 2008, 02:19 PM
Hello David,

If you are rebinding RadGrid somewhere in the initialization lifecylce (prior to rendering) then RadGrid might recreate its items twice. To make sure this does not happen, you can loop through the data items in the PreRender event instead:

void RadGrid1_PreRender(object sender, EventArgs e) 
    foreach (GridDataItem item in RadGrid1.MasterTableViewItems) 
    { 
        DocumentList.Add(item.DataItem[0]); 
    } 

Please see if this works successfully.

Regards,
Veli
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
David
Top achievements
Rank 1
answered on 04 Aug 2008, 02:26 PM
This may work, but I am having trouble with the PreRender Sub recognizing the code you have given.  Writing this in asp.net 2.0 in vb syntax.
0
David
Top achievements
Rank 1
answered on 04 Aug 2008, 02:35 PM
Any help would be much appreciated.  Thank you.
0
Accepted
Sebastian
Telerik team
answered on 04 Aug 2008, 02:59 PM
Hi David,

You can convert the code to VB.NET language using our free online converter. Here is the result:

Sub RadGrid1_PreRender(ByVal sender As ObjectByVal e As EventArgs) Handles RadGrid1.PreRender 
    For Each item As GridDataItem In RadGrid1.MasterTableViewItems 
        DocumentList.Add(item.DataItem(0)) 
    Next 
End Sub 

Best regards,
Stephen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
David
Top achievements
Rank 1
answered on 04 Aug 2008, 03:11 PM
Using the code provided, I get the following error.

"MasterTableViewItems" is not a member of "Telerik.RadControls.RadGrid".

I appreciate the help.
0
David
Top achievements
Rank 1
answered on 04 Aug 2008, 03:15 PM
I think I figured out the above problem.  It should be 'MasterTableView.Items'.

However the code throws and exception for object not set to an instance of an object.  Not sure why it is throwing the exception.  Arraylist is correctly declared.

Is there something I am missing here?  Thanks again for the help.
0
David
Top achievements
Rank 1
answered on 04 Aug 2008, 05:48 PM
I figured it out.  Thanks again! I had something missing.
Tags
Grid
Asked by
David
Top achievements
Rank 1
Answers by
Veli
Telerik team
David
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or