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

[Solved] Multiple grids in a listView do not fire the ItemDataBound event

1 Answer 64 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ams
Top achievements
Rank 1
Ams asked on 03 Apr 2014, 01:59 PM


I am trying to add multiple Telerik RadGrid to a listView.
On the initial addition it fires the RadGrid ItemDataBound event.
However, when users click to add another, nothing gets added on the
screen since the event is not fired if there are multiple grids.

'// This is called after users click to add a new grid
Protected Sub LVScenarios_ItemDataBound(sender As Object, e As RadListViewItemEventArgs) Handles LVScenarios.ItemDataBound
    If TypeOf e.Item Is RadListViewDataItem Then
        Dim scenarioGrid As RadGrid = DirectCast(e.Item.FindControl("GVScenarios"), RadGrid)
        If Not scenarioGrid Is Nothing Then
 
            AddHandler scenarioGrid.ItemDataBound, AddressOf scenarioGrid_ItemDataBound
 
            scenarioGrid.DataSource = scenarioDataSource
            scenarioGrid.DataBind()
 
             '// If only one gird in the LVScenarios datasource, then the grid itemDataBound is fired, if more than one it is skipped and nothing ends up on the screen
 
        End If
    End If
End Sub

1 Answer, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 08 Apr 2014, 08:48 AM
Hello Ams,

The reason for that exception is that you are binding the grid too late in the page live cycle. I would recommend you to use advanced data-binding through NeedDataSource event handler as described in the following help article. Initially you could set an empty data source and on ItemDataBound of the ListView to call Rebind() method of the grid and in the NeedDataSource to pass the correct data.

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Ams
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Share this question
or