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

Pre Render Event looping through many items

1 Answer 90 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Aret asked on 21 Aug 2012, 07:57 PM
I have this code in the Pre Render event in one of my RadGrids.............

 For Each item As GridDataItem In Radgrid_AddRemoveProvider.MasterTableView.Items
            Dim lblPID As Label = DirectCast(item.FindControl("lblPID"), Label)

            Dim btnAddProvider As LinkButton = DirectCast(item.FindControl("btnAddProvider"), LinkButton)
            Dim btnRemoveProvider As LinkButton = DirectCast(item.FindControl("btnRemoveProvider"), LinkButton)
            Dim lblFullName As Label = DirectCast(item.FindControl("lblFullName"), Label)
            Dim btnFullName As LinkButton = DirectCast(item.FindControl("btnFullName"), LinkButton)
            '  Dim lblContactType As Label = DirectCast(item.FindControl("lblContactType"), Label)
            ' Dim ddPreferredContact As DropDownList = DirectCast(item.FindControl("ddPreferredContact"), DropDownList)

            If lblPID.Text = Nothing Then
                btnAddProvider.Visible = True
                'ddPreferredContact.Visible = True
                'lblContactType.Visible = False
                btnRemoveProvider.Visible = False
                lblFullName.Visible = True
                btnFullName.Visible = False
            ElseIf lblPID.Text <> Nothing Then
                btnAddProvider.Visible = False
                'ddPreferredContact.Visible = False
                'lblContactType.Visible = True
                btnRemoveProvider.Visible = True
                lblFullName.Visible = False
                btnFullName.Visible = True
            End If


However it loops through this code 100 times looping through each item in my RadGrid.  The problem is that it goes through this loop every time I perform any sort of event on the page.  Is there anyway I can tell it to stop looping through this code when i am not working with this RadGrid on the page.  I tried putting the code in the ItemCreated event, but it does the same thing. Overall I believe this is effecting the performance and speed of my page. 

1 Answer, 1 is accepted

Sort by
Top achievements
Rank 2
answered on 22 Aug 2012, 05:35 AM
Hi Aret,

Please try the same functionality inside the ItemDataBound event of RadGrid.

Protected Sub Radgrid_AddRemoveProvider_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs)
    If TypeOf e.Item Is GridDataItem Then      
        Dim ditem As GridDataItem = DirectCast(e.Item, GridDataItem)
                'your code
    End If
End Sub

Asked by
Top achievements
Rank 1
Answers by
Top achievements
Rank 2
Share this question